Skip to content

Commit c6690cc

Browse files
committed
feat: DelimitedStringsOption now panics if an empty delimiter is passed in
1 parent e2c3e22 commit c6690cc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

option.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,22 @@ func StringOption(names ...string) Option {
199199

200200
// StringsOption is a command option that can handle a slice of strings
201201
func StringsOption(names ...string) Option {
202-
return DelimitedStringsOption("", names...)
202+
return &stringsOption{
203+
Option: NewOption(Strings, names...),
204+
delimiter: "",
205+
}
203206
}
204207

205208
// DelimitedStringsOption like StringsOption is a command option that can handle a slice of strings.
206209
// However, DelimitedStringsOption will automatically break up the associated CLI inputs based on the delimiter.
207210
// For example, instead of passing `command --option=val1 --option=val2` you can pass `command --option=val1,val2` or
208211
// even `command --option=val1,val2 --option=val3,val4`.
209212
//
210-
// A delimiter of "" means that no delimiter is used
213+
// A delimiter of "" is invalid
211214
func DelimitedStringsOption(delimiter string, names ...string) Option {
215+
if delimiter == "" {
216+
panic("cannot create a DelimitedStringsOption with no delimiter")
217+
}
212218
return &stringsOption{
213219
Option: NewOption(Strings, names...),
214220
delimiter: delimiter,

0 commit comments

Comments
 (0)