Skip to content

Commit bc71fdd

Browse files
authored
fix: allow setting slice default values (#4)
Signed-off-by: Donnie Adams <[email protected]>
1 parent f16f185 commit bc71fdd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

builder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ func command(obj Runnable, parentEnv string, children ...any) *cobra.Command {
186186
switch fieldType.Tag.Get("split") {
187187
case "false":
188188
arrays[name] = v
189-
flags.StringArrayP(name, alias, nil, usage)
189+
flags.StringArrayP(name, alias, []string{defValue}, usage)
190190
default:
191191
slices[name] = v
192-
flags.StringSliceP(name, alias, nil, usage)
192+
var val []string
193+
if len(defValue) > 0 {
194+
val = strings.Split(defValue, ",")
195+
}
196+
flags.StringSliceP(name, alias, val, usage)
193197
}
194198
case reflect.Map:
195199
switch fieldType.Tag.Get("boolmap") {

0 commit comments

Comments
 (0)