go-flags icon indicating copy to clipboard operation
go-flags copied to clipboard

Feature Request: Add ability to specify delimiter for slice flags

Open pcman312 opened this issue 8 years ago • 1 comments

When specifying a slice flag:

Strs []string `short:"s" long:"strs" description:"..."

there doesn't appear to be a way to specify a delimiter to use to split the provided strings into the string slice. For instance, if the above flag is specified:

./program -s one,two -s three

Results in:

0: one,two
1: three

Instead of:

0: one
1: two
2: three

The typical way to do this is to specify -s multiple times. Adding the ability to split the arguments by a delimiter would be a big usability improvement, particularly when you need to specify many arguments into that slice.

There currently is the env-delim option which appears to have a similar functionality. I propose to add a delim option that will split the flag values by the given delimiter.

pcman312 avatar Sep 13 '17 17:09 pcman312

Also, I would personally add a size tag that would enforce slice (or maybe additionally, string size) arguments. Could be a range or a single integer. e.g. size:"3" size:"1,-" size:"-,4" size"3,5"

oguzyildizz avatar Oct 08 '18 18:10 oguzyildizz