Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map valued (string->string, string->int) flags. #133

Merged
merged 1 commit into from Aug 15, 2018
Merged

Add map valued (string->string, string->int) flags. #133

merged 1 commit into from Aug 15, 2018

Conversation

tamalsaha
Copy link

@tamalsaha tamalsaha commented Aug 10, 2017

Format: --myflag=a=1,b=2

ref: #129

@CLAassistant
Copy link

CLAassistant commented Aug 10, 2017

CLA assistant check
All committers have signed the CLA.

@tamalsaha tamalsaha changed the title Add string->int flag Add map valued (string->string, string->int) flags. Aug 16, 2017
@tamalsaha
Copy link
Author

@eparis, mind taking a look?

@tamalsaha tamalsaha closed this Jul 11, 2018
@sgraham785
Copy link

@tamalsaha why was this closed? it's still a useful implementation unless there is now some other way to accomplish now?

@tamalsaha
Copy link
Author

Because it did not seem that it will get merged. Our fork is maintained.

@eparis
Copy link
Collaborator

eparis commented Aug 15, 2018

somehow I totally missed this.... sorry....

@eparis eparis reopened this Aug 15, 2018

// Format: a=1,b=2
func (s *stringToStringValue) Set(val string) error {
ss := strings.Split(val, ",")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this actually be a CSV decode, instead of just splitting on ,? What is there is a comma in the value?

@tamalsaha
Copy link
Author

Thanks @eparis ! I have addressed your comment. PTAL.

@eparis
Copy link
Collaborator

eparis commented Aug 15, 2018

that's really awesome! If you'll write a test of the csv stuff, I'll merge it!

@tamalsaha
Copy link
Author

@tamalsaha
Copy link
Author

Added even more tests, Search for 5,6, 7,8 . PTAL.

@eparis eparis merged commit 947b89b into spf13:master Aug 15, 2018
@sgraham785
Copy link

this is awesome thanks guys! 💯

@yashbhutwala
Copy link

yashbhutwala commented May 16, 2019

@tamalsaha Does StringToStringVar support --myflag=a=1,b=2,3. I tried it and it didn't work for me, so not sure, if I'm using it wrong, or the functionality is missing.

@tamalsaha
Copy link
Author

It is not supported.See the comment #179

@yashbhutwala
Copy link

I see, OK. This comment indicates that --f3 "c=5,6",d=7 is possible, however, I haven't been able to use it.

@tamalsaha
Copy link
Author

Try passing this flag like this --myflag a=1,"b=2,3" . It should work.

@yashbhutwala
Copy link

yashbhutwala commented May 17, 2019

Nope, getting an error: flag: 3 must be formatted as key=value

@tamalsaha
Copy link
Author

tamalsaha commented May 17, 2019

Here is the code that does the parsing. https://github.com/spf13/pflag/pull/179/files#diff-1ace98db8b8888abf672baa63775bc05R24

This should work: https://play.golang.org/p/rIAPpDsiHJQ The code is using CSV reader. Did you use the double quote?

@yashbhutwala
Copy link

yashbhutwala commented May 17, 2019

OK @tamalsaha this worked for me: --f3 'a=1,"b=5,6"'. So instead of `` wrapping the whole parameter, it's ''. Thanks so much for your swift responses! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants