Skip to content

Commit 8f41a38

Browse files
committed
Allow setting map[string][]string from the command line
Signed-off-by: Ciprian Hacman <[email protected]>
1 parent e3cbe11 commit 8f41a38

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

util/pkg/reflectutils/access.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ func setType(v reflect.Value, newValue string) error {
147147
name, value, _ := strings.Cut(newValue, "=")
148148
v.SetMapIndex(reflect.ValueOf(name), reflect.ValueOf(intstr.Parse(value)))
149149

150+
case "map[string][]string":
151+
name, value, _ := strings.Cut(newValue, "=")
152+
tokens := strings.Split(value, ",")
153+
valueArray := reflect.MakeSlice(reflect.TypeOf(tokens), 0, v.Len()+len(tokens))
154+
for _, s := range tokens {
155+
valueItem := reflect.New(reflect.TypeOf(s))
156+
if err := setType(valueItem.Elem(), s); err != nil {
157+
return err
158+
}
159+
valueArray = reflect.Append(valueArray, valueItem.Elem())
160+
}
161+
v.SetMapIndex(reflect.ValueOf(name), valueArray)
162+
150163
default:
151164
return fmt.Errorf("unhandled type %q", t)
152165
}

0 commit comments

Comments
 (0)