diff --git a/cmd/nvidia-ctk/config/config.go b/cmd/nvidia-ctk/config/config.go index 3c4555f41..58e053ebc 100644 --- a/cmd/nvidia-ctk/config/config.go +++ b/cmd/nvidia-ctk/config/config.go @@ -38,7 +38,8 @@ type command struct { // options stores the subcommand options type options struct { flags.Options - sets cli.StringSlice + setSliceSeparator string + sets cli.StringSlice } // NewCommand constructs an config command with the specified logger @@ -72,9 +73,16 @@ func (m command) build() *cli.Command { }, &cli.StringSliceFlag{ Name: "set", - Usage: "Set a config value using the pattern key=value. If value is empty, this is equivalent to specifying the same key in unset. This flag can be specified multiple times", + Usage: "Set a config value using the pattern key=value. If value is empty, this is equivalent to specifying the same key in unset. This flag can be specified multiple times. If the setting represents a slice, the elements are semi-colon-separated.", Destination: &opts.sets, }, + &cli.StringFlag{ + Name: "set-slice-separator", + Usage: "Specify a separator for slices applied using the set command.", + Hidden: true, + Value: ";", + Destination: &opts.setSliceSeparator, + }, &cli.BoolFlag{ Name: "in-place", Aliases: []string{"i"}, @@ -96,6 +104,13 @@ func (m command) build() *cli.Command { return &c } +func validateFlags(c *cli.Context, opts *options) error { + if opts.setSliceSeparator == "" { + return fmt.Errorf("set-slice-separator must be set") + } + return nil +} + func run(c *cli.Context, opts *options) error { cfgToml, err := config.New( config.WithConfigFile(opts.Config), @@ -105,7 +120,7 @@ func run(c *cli.Context, opts *options) error { } for _, set := range opts.sets.Value() { - key, value, err := setFlagToKeyValue(set) + key, value, err := setFlagToKeyValue(set, opts.setSliceSeparator) if err != nil { return fmt.Errorf("invalid --set option %v: %w", set, err) } @@ -139,7 +154,7 @@ var errInvalidFormat = errors.New("invalid format") // setFlagToKeyValue converts a --set flag to a key-value pair. // The set flag is of the form key[=value], with the value being optional if key refers to a // boolean config option. -func setFlagToKeyValue(setFlag string) (string, interface{}, error) { +func setFlagToKeyValue(setFlag string, setSliceSeparator string) (string, interface{}, error) { setParts := strings.SplitN(setFlag, "=", 2) key := setParts[0] @@ -172,7 +187,7 @@ func setFlagToKeyValue(setFlag string) (string, interface{}, error) { case reflect.String: return key, value, nil case reflect.Slice: - valueParts := strings.Split(value, ",") + valueParts := strings.Split(value, setSliceSeparator) switch field.Elem().Kind() { case reflect.String: return key, valueParts, nil