pflag icon indicating copy to clipboard operation
pflag copied to clipboard

Parse string map values

Open fuhrmannb opened this issue 8 years ago • 4 comments

In cobra, I have a use case where I want to parse a string map from command line as follow:

$ mycommand --string-map-option "a=b,c=d"

I haven't seen any method into pflag to parse the result as map[string]string.

For now, I have implemented in my project a basic version that satisfies pflag.Value interface. I use FlagSet.Var() method to use the previous value and it's working well.

It will be interesting to directly have this parser into pflag package. I think this flag parser can be helpful to the community. If you are OK with this idea, I can propose a Pull Request based on my current implementation.

fuhrmannb avatar May 06 '17 12:05 fuhrmannb

We would like this. I think there are common use-cases for both string-> string and string -> int flags.

tamalsaha avatar Aug 09 '17 18:08 tamalsaha

I also have a need for this.

frankgreco avatar Jun 18 '18 20:06 frankgreco

FYI: @eparis if you feel the work accomplished in #133 properly addresses the OP issue here this could probably be closed

sgraham785 avatar Aug 16 '18 06:08 sgraham785

Reading this thread now, I have a question: In case of -flag a=x,a=y the variable p(map[string]string) only has a=y and ignores a=x which I think is a bad user experience. Is this expected? @tamalsaha @eparis Any suggestions to avoid this?

lokesh-confluent avatar Jun 26 '23 16:06 lokesh-confluent