Skip to content

Add support for mutual exclusive options #199

@remkop

Description

@remkop

Something 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions