feat: add PatchArgs API type to populate patch options

This commit converts the Options section of a patch into an object instead of map.
This allows better clarification of the available options.
This commit is contained in:
Adoram Shoval
2025-05-23 14:28:43 -04:00
parent 2859474e3c
commit 9043c223d4
8 changed files with 93 additions and 143 deletions

View File

@@ -3,8 +3,6 @@
package types
import "reflect"
// Patch represent either a Strategic Merge Patch or a JSON patch
// and its targets.
// The content of the patch can either be from a file
@@ -20,15 +18,17 @@ type Patch struct {
Target *Selector `json:"target,omitempty" yaml:"target,omitempty"`
// Options is a list of options for the patch
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
Options *PatchArgs `json:"options,omitempty" yaml:"options,omitempty"`
}
// Equals return true if p equals o.
func (p *Patch) Equals(o Patch) bool {
targetEqual := (p.Target == o.Target) ||
(p.Target != nil && o.Target != nil && *p.Target == *o.Target)
optionsEqual := (p.Options == o.Options) ||
(p.Options != nil && o.Options != nil && *p.Options == *o.Options)
return p.Path == o.Path &&
p.Patch == o.Patch &&
targetEqual &&
reflect.DeepEqual(p.Options, o.Options)
optionsEqual
}