Add support for mutual exclusive options
See original GitHub issueSomething like this:
@Command(autoHelp = true, sortOptions = false, groups = {
@OptionGroup(name = "dest", required = true, exclusive = true,
heading = "Destination: The data can be sent either to a file or to a socket"),
@OptionGroup(name = "other",
heading = "Other:%n Some other options")})
class ExclusiveOptionsExample {
@Option(names = "-f", description = "Target file", group = "dest")
File file;
@Option(names = "-s", description = "Target socket", group = "dest")
InetAddress adr;
@Option(names = "-d", description = "Data file", group = "other")
File data;
}
Usage help:
Usage: <main class> [-hV] [-d=<data>] (-f=<file> | -s=<adr>)
Destination: The data can be sent either to a file or to a socket
-f= <file> Target file
-s= <adr> Target socket
Other:
Some other options
-d= <data> Data file
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
Commands:
help Displays help information about the specified command
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:16 (11 by maintainers)
Top Results From Across the Web
Mutually exclusive command line options - python
I want to achieve something like if -i option and "ifile" is present or -p and fcsname is present..at input, then it is...
Read more >Mutually Exclusive: What It Means, With Examples
If considering mutually exclusive options, a company must weigh the opportunity cost, or what it would be giving up by choosing each option....
Read more >mutuallyExclusiveOptions
Declare a set of two or more mutually exclusive options. If none of the options are given on the command line, the value...
Read more >Mutually Exclusive Campaigns
Click the gear icon ⚙ on the top right, and go to CAMPAIGN SETTINGS. Under the Mutually Exclusive Groups section, click Create mutually...
Read more >Mutually Exclusive Events - Math is Fun
Let's look at the probabilities of Mutually Exclusive events. But first, a definition: Probability of an event happening = Number of ways it...
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
A first cut of support for
ArgGroup
s has landed in master. This adds support for:exclusive = true
)exclusive = false
: require all elements in the group, or none) as requested in #295Example:
This defines a composite group with the following synopsis:
The composite group consists of the required exclusive group
(-x | -y)
and the required co-occurring group(-a -b)
.Valid user input for this group would be:
Any other combination of -x, -y, -a and -b would give a validation error.
Still TODO:
picocli-codegen
to build a model from the new annotations at compile timeThat said, the majority of the functionality is there. I would appreciate it if people would try this to see if it meets their requirements and to find any places where the API, error messages or anything else should be improved.
Also: Sometimes its common to have a single option as an alternative with a group of options. Like in the below
-u
,-p
,-c
are only required if-P
(profile) is not present.