package ckconfig import ( "fmt" "strings" commandkit "go.maximumdirect.net/commandkit" configkit "go.maximumdirect.net/configkit" ) func supportsOverrides[I, S any](prepared *preparedSuite[I, S], operation Operation) bool { for _, scope := range prepared.scopes { if scope.scope.Features.Overrides && containsOperation(scope.scope.Operations, operation) { return true } } return false } func overrideParser(flag string) func(string) (configkit.Override, error) { return func(raw string) (configkit.Override, error) { pointer, jsonText, ok := strings.Cut(raw, "=") if !ok { return configkit.Override{}, fmt.Errorf("override requires POINTER=JSON") } path, err := configkit.ParsePath(pointer) if err != nil { return configkit.Override{}, fmt.Errorf("invalid override path: %w", err) } value, err := commandkit.ParseCLIJSON(jsonText) if err != nil { return configkit.Override{}, fmt.Errorf("invalid override JSON: %w", err) } return configkit.Override{Path: path, Value: value, Flag: flag}, nil } } func cloneSelection(selection Selection) Selection { if selection.Overrides != nil { selection.Overrides = append([]configkit.Override(nil), selection.Overrides...) for index := range selection.Overrides { selection.Overrides[index].Value = cloneCLIValue(selection.Overrides[index].Value) } } return selection } func cloneCLIValue(value any) any { switch value := value.(type) { case []any: copy := make([]any, len(value)) for index, element := range value { copy[index] = cloneCLIValue(element) } return copy case map[string]any: copy := make(map[string]any, len(value)) for key, element := range value { copy[key] = cloneCLIValue(element) } return copy default: return value } }