public class CommandLineParser extends Object
A command-line parser which supports a command/sub-command style command-line interface. Supports the following syntax:
<option>* (<sub-command> <sub-command-option>*)*
-a
.--long-option
.-a arg
or
--long arg
.-a=arg
or --long=arg
.-aarg
.-ab
is equivalent to -a -b
.-
character.ParsedCommandLine.getExtraArguments()
to obtain the non-option command-line arguments.Constructor and Description |
---|
CommandLineParser() |
CommandLineParser(Writer deprecationPrinter) |
Modifier and Type | Method and Description |
---|---|
CommandLineParser |
allowMixedSubcommandsAndOptions() |
CommandLineParser |
allowUnknownOptions() |
CommandLineOption |
option(String... options)
Defines a new option.
|
ParsedCommandLine |
parse(Iterable<String> commandLine)
Parses the given command-line.
|
ParsedCommandLine |
parse(String... commandLine)
Parses the given command-line.
|
void |
printUsage(Appendable out)
Prints a usage message to the given stream.
|
public CommandLineParser()
public CommandLineParser(Writer deprecationPrinter)
public ParsedCommandLine parse(String... commandLine) throws CommandLineArgumentException
commandLine
- The command-line.CommandLineArgumentException
- On parse failure.public ParsedCommandLine parse(Iterable<String> commandLine) throws CommandLineArgumentException
commandLine
- The command-line.CommandLineArgumentException
- On parse failure.public CommandLineParser allowMixedSubcommandsAndOptions()
public CommandLineParser allowUnknownOptions()
public void printUsage(Appendable out)
out
- The output stream to write to.public CommandLineOption option(String... options)
options
- The options values.Copyright © 2016–2021 The Apache Software Foundation. All rights reserved.