Skip to content

Commit

Permalink
feat: DelimitedStringsOption now panics if an empty delimiter is pass…
Browse files Browse the repository at this point in the history
…ed in
  • Loading branch information
aschmahmann committed Jan 26, 2021
1 parent e2c3e22 commit c6690cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,22 @@ func StringOption(names ...string) Option {

// StringsOption is a command option that can handle a slice of strings
func StringsOption(names ...string) Option {
return DelimitedStringsOption("", names...)
return &stringsOption{
Option: NewOption(Strings, names...),
delimiter: "",
}
}

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

0 comments on commit c6690cc

Please sign in to comment.