From 89858eea56d1e06105c3a6d1f4b99e4e248ff064 Mon Sep 17 00:00:00 2001 From: Patrick Zheng Date: Mon, 31 Oct 2022 13:44:20 +0800 Subject: [PATCH] updated per code review Signed-off-by: Patrick Zheng --- cmd/notation/verify.go | 2 +- internal/cmd/flags.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/notation/verify.go b/cmd/notation/verify.go index e51cd5226..4d4f66086 100644 --- a/cmd/notation/verify.go +++ b/cmd/notation/verify.go @@ -44,7 +44,7 @@ notation verify [--plugin-config =...] [--username ] [--pa }, } opts.ApplyFlags(command.Flags()) - command.Flags().StringArrayVarP(&opts.pluginConfig, "plugin-config", "c", []string{}, "{key}={value} pairs that are passed as it is to a plugin, if the verification is associated with a verification plugin, refer plugin documentation to set appropriate values") + command.Flags().StringArrayVarP(&opts.pluginConfig, "plugin-config", "c", nil, "{key}={value} pairs that are passed as it is to a plugin, if the verification is associated with a verification plugin, refer plugin documentation to set appropriate values") return command } diff --git a/internal/cmd/flags.go b/internal/cmd/flags.go index f3a4c12b6..5afbcaec8 100644 --- a/internal/cmd/flags.go +++ b/internal/cmd/flags.go @@ -77,7 +77,7 @@ var ( Usage: "{key}={value} pairs that are passed as it is to a plugin, refer plugin's documentation to set appropriate values", } SetPflagPluginConfig = func(fs *pflag.FlagSet, p *[]string) { - fs.StringArrayVarP(p, PflagPluginConfig.Name, PflagPluginConfig.Shorthand, []string{}, PflagPluginConfig.Usage) + fs.StringArrayVarP(p, PflagPluginConfig.Name, PflagPluginConfig.Shorthand, nil, PflagPluginConfig.Usage) } ) @@ -90,11 +90,11 @@ type KeyValueSlice interface { func ParseFlagPluginConfig(config []string) (map[string]string, error) { pluginConfig := make(map[string]string, len(config)) for _, pair := range config { - index := strings.Index(pair, "=") - if index <= 0 { + key, val, found := strings.Cut(pair, "=") + if !found || key == "" || val == "" { return nil, fmt.Errorf("could not parse flag %s: key-value pair requires \"=\" as separator", PflagPluginConfig.Name) } - pluginConfig[pair[:index]] = pair[index+1:] + pluginConfig[key] = val } return pluginConfig, nil }