flaggy icon indicating copy to clipboard operation
flaggy copied to clipboard

Support slice flag inputs with commas

Open integrii opened this issue 5 years ago • 3 comments

Currently, slice flags are required to be specified multiple times. It could be helpful though to automatically parse commas in slice flag inputs into different values. Then again, it could make passing literal commas more confusing.

Should we support slice inputs like this: ./app -str one,two which results in []string{"one","two"}

or should we continue to only support multiple flag uses like this: ./app -str one -str two which results in the same [string{"one","two"}

integrii avatar May 23 '19 05:05 integrii

The StringSlice flag was already modified to split on commas, but we may want to revert that if we want commas to remain literals as originally designed: https://github.com/integrii/flaggy/commit/b5bd28929feea25250a7b6c411844d54eda34b99

integrii avatar May 23 '19 06:05 integrii

I think we could keep the default comma parsing behavior here while adding a new string slice flag type that takes commas directly without considering them a character to split input on.

integrii avatar Oct 23 '19 22:10 integrii

An alternative could be what the stdlib flag does, which is to define a Value interface with a Set(string) error method that anybody can implement on their own types. That brings the possibility of projects such as https://pkg.go.dev/github.com/sgreben/flagvar to create Values for different use cases and the library does not need to support them all.

jdevera avatar Jun 05 '22 22:06 jdevera