Skip to content

Commit

Permalink
Merge pull request #1998 from carolynvs/stringArray
Browse files Browse the repository at this point in the history
Support stringArray cobra flag type
  • Loading branch information
carolynvs committed Apr 1, 2022
2 parents ff1351a + 09cb6ab commit b5b2e43
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func getViperValue(flags *pflag.FlagSet, f *pflag.Flag) interface{} {
var err error

// This is not an exhaustive list, if we need more types supported, it'll panic, and then we can add it.
switch f.Value.Type() {
flagType := f.Value.Type()
switch flagType {
case "int":
out, err = flags.GetInt(f.Name)
case "string":
Expand All @@ -76,12 +77,14 @@ func getViperValue(flags *pflag.FlagSet, f *pflag.Flag) interface{} {
out, err = flags.GetBool(f.Name)
case "stringSlice":
out, err = flags.GetStringSlice(f.Name)
case "stringArray":
out, err = flags.GetStringArray(f.Name)
default:
panic(errors.Errorf("unsupported type for conversion between flag %s and viper configuration: %T", f.Name, f.Value.Type()))
panic(errors.Errorf("unsupported type for conversion between flag %s and viper configuration: %T", f.Name, flagType))
}

if err != nil {
panic(errors.Wrapf(err, "error parsing config key %s as %T", f.Name, f.Value.Type()))
panic(errors.Wrapf(err, "error parsing config key %s as %T", f.Name, flagType))
}

return out
Expand Down

0 comments on commit b5b2e43

Please sign in to comment.