question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to define an option to accept only one value, but allow to use it multiple times?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
remkopcommented, Sep 22, 2017

If only one value is allowed, why not make it a String instead of a List?

@Option(names = { "-o", "--open" })
private String files = null;

Now, if the option is specified multiple times, picocli will throw a OverwrittenOptionException by default, but you can make it lenient by calling CommandLine.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

0reactions
RobertZenzcommented, Oct 1, 2017

I’ve just build the latest master (39f1944) and it works, thank you very very much for the fast response.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found