public class CommandLine extends java.lang.Object
The GNU syntax is implemented as follows. There are short (single character) and long (multi character) options, just as provided by the AOption annotation. Short options are introduced using a single minus (e.g. '-h') while long options are introduced using a double minus (e.g. '--help'). The parameter for an option is either the next argument, or--in case of long options--possibly separated by an equals sign (e.g. '--file=test.txt'). Short options may be chained (e.g. '-xvf abc' instead of '-x -v -f abc'). For chained short options, only the last option may take a parameter. The separator '--' may be used to switch off argument processing for the remaining arguments, i.e. all other arguments are treated as left-overs.
Constructor and Description |
---|
CommandLine(OptionRegistry registry)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
parse(CommandLineTokenStream ts)
Parses the command line parameters implicitly given by the token stream and
applies the options found.
|
java.lang.String[] |
parse(java.lang.String[] args)
Parses the given command line parameters and applies the options found.
|
void |
printUsage(java.io.PrintWriter pw)
Print the list of all supported options using reasonable default values for
widths.
|
void |
printUsage(java.io.PrintWriter pw,
int firstCol,
int width)
Print the list of all supported options.
|
public CommandLine(OptionRegistry registry)
registry
- Registry containing the options to be used by this instance.public java.lang.String[] parse(java.lang.String[] args) throws OptionException
OptionException
is thrown.args
- the command line arguments to be parsed.OptionException
- in case of syntax errors or invalid parameters.public java.lang.String[] parse(CommandLineTokenStream ts) throws OptionException
ts
- Token stream containing the arguments.OptionException
- in case of syntax errors or invalid parameters.public void printUsage(java.io.PrintWriter pw)
pw
- the writer used for output.public void printUsage(java.io.PrintWriter pw, int firstCol, int width)
pw
- the writer to print to.firstCol
- the width of the first column containing the option name (without
the trailing space).width
- the maximal width of a line (aka terminal width).