-
Notifications
You must be signed in to change notification settings - Fork 424
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
How to pass multiple values to a Map? #753
Comments
Looks like you need to add |
Shouldn't this be the default for a |
Picking good defaults is always tricky. I’m aware that JCommander splits automatically, and this may trip up people migrating from JCommander to picocli. That would be an argument for splitting by default. (Were you using JCommander previously?) Currently picocli doesn’t split unless you tell it to. The drawback is somewhat more verbosity, the benefit is self-documentation: it’s clear which options split and which don’t, and it’s clear what the separator is. |
I wasn't in JCommander, I was just expecting a |
I see, yes, the map docs don't have an example that uses a split regex. Let's improve that. Do you think you'll be able to provide a patch or pull request? |
I don't think I can because I am not familiar with all the docs references that can be impacted by this issue, so I am afraid I might leave one out. |
I was thinking to just add an example to the section on Maps (from line 614 in https://github.com/remkop/picocli/blob/master/docs/index.adoc). I don't think there are any references. The HTML is generated from that AsciiDoc file (run |
Alternatively, you can help by providing the text/example code in a comment here, and I will take care of integrating it into the user manual. |
This is easier for me now. I would add something like this at the end of the map section: Be aware that if you wish to parse a multi-valued -m role=admin,level=10,enabled=true You have to define your @options configurations as: @Option(names = {"-m", "--map"}, split = ",", description = "A map of multiple values.")
private Map<String, String> map; Which will be converted to a |
Cool, thank you! I'll update here after I merged this in (hopefully tonight). |
I decided to improve the example in the Split Regex section of the user manual, and point to that section from the Maps section (and also from the Arrays and Collections section). Thanks for calling this out! 👍 |
Thank you, it was my pleasure :) |
I have a
Map<String, Object>
object that's supposed to hold variables such as"role","admin"
,"level","10"
,"enabled","true"
.I tried to define it like:
And call it like this in cli:
But this results in a map of:
"role"
->"admin,level=10,enabled=true"
What's the correct way to call it in the cli to get the full map of values?
The text was updated successfully, but these errors were encountered: