How to define an option to accept only one value, but allow to use it multiple times?
See original GitHub issueI can’t figure out how to define an option which does accept only one value but can be specified multiple times. To be exact:
application -o value1 -o value2 parameter1 parameter2
When defined without arity, parameter1
and parameter2
are added to o
. I tried this:
@Option(names = { "-o", "--open" }, arity = "1")
private List<String> files = null;
But that disallows multiple usage of -o
.
How can I define this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (22 by maintainers)
Top Results From Across the Web
Can an Option in a Select tag carry multiple values?
One way to do this, first one an array, 2nd an object: <select name=""> <option value='{"num_sequence":[0,1,2,3]}'>Option one</option> <option ...
Read more >Apply data validation to cells - Microsoft Support
Try it! Select the cell(s) you want to create a rule for. Select Data >Data Validation. Data Validation. On the Settings tab, under...
Read more >What are Options? Types, Spreads, Example, and Risk Metrics
Options are financial derivatives that give the buyer the right to buy or sell the underlying asset at a stated price within a...
Read more >Options — Click Documentation (8.1.x)
When passing a default with multiple=True , the default value must be a list or tuple, otherwise it will be interpreted as a...
Read more >clap::Arg - Rust - Docs.rs
--option val1 val2 is a single occurrence with multiple values. ... is to specify that -F only accepts one value, but is allowed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If only one value is allowed, why not make it a String instead of a List?
Now, if the option is specified multiple times, picocli will throw a
OverwrittenOptionException
by default, but you can make it lenient by callingCommandLine.setOverwrittenOptionsAllowed(true)
before parsing the input.This way the last option value specified on the command line is preserved.
See also http://picocli.info/#_too_many_values
I’ve just build the latest master (39f1944) and it works, thank you very very much for the fast response.