Package org.apache.maven.wrapper.cli
Class CommandLineParser
java.lang.Object
org.apache.maven.wrapper.cli.CommandLineParser
A command-line parser which supports a command/sub-command style command-line interface. Supports the following syntax:
<option>* (<sub-command> <sub-command-option>*)*
- Short options are a '-' followed by a single character. For example:
-a
. - Long options are '--' followed by multiple characters. For example:
--long-option
. - Options can take arguments. The argument follows the option. For example:
-a arg
or--long arg
. - Arguments can be attached to the option using '='. For example:
-a=arg
or--long=arg
. - Arguments can be attached to short options. For example:
-aarg
. - Short options can be combined. For example
-ab
is equivalent to-a -b
. - Anything else is treated as an extra argument. This includes a single
-
character. - '--' indicates the end of the options. Anything following is not parsed and is treated as extra arguments.
- The parser is forgiving, and allows '--' to be used with short options and '-' to be used with long options.
- The set of options must be known at parse time. Sub-commands and their options do not need to be known at parse
time. Use
ParsedCommandLine.getExtraArguments()
to obtain the non-option command-line arguments.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionDefines a new option.Parses the given command-line.Parses the given command-line.void
printUsage
(Appendable out) Prints a usage message to the given stream.
-
Constructor Details
-
CommandLineParser
public CommandLineParser() -
CommandLineParser
-
-
Method Details
-
parse
Parses the given command-line.- Parameters:
commandLine
- The command-line.- Returns:
- The parsed command line.
- Throws:
CommandLineArgumentException
- On parse failure.
-
parse
Parses the given command-line.- Parameters:
commandLine
- The command-line.- Returns:
- The parsed command line.
- Throws:
CommandLineArgumentException
- On parse failure.
-
allowMixedSubcommandsAndOptions
-
allowUnknownOptions
-
printUsage
Prints a usage message to the given stream.- Parameters:
out
- The output stream to write to.
-
option
Defines a new option. By default, the option takes no arguments and has no description.- Parameters:
options
- The options values.- Returns:
- The option, which can be further configured.
-