public abstract class Parser extends java.lang.Object implements CommandLineParser
Parser
creates CommandLine
s.
Parser
Modifier and Type | Field and Description |
---|---|
private CommandLine |
cmd
commandline instance
|
private Options |
options
current Options
|
private java.util.List |
requiredOptions
list of required options strings
|
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
private void |
checkRequiredOptions()
Throws a
MissingOptionException if all of the
required options are no present. |
protected abstract java.lang.String[] |
flatten(Options opts,
java.lang.String[] arguments,
boolean stopAtNonOption)
Subclasses must implement this method to reduce
the
arguments that have been passed to the parse
method. |
CommandLine |
parse(Options options,
java.lang.String[] arguments)
Parses the specified
arguments
based on the specifed Options . |
CommandLine |
parse(Options options,
java.lang.String[] arguments,
boolean stopAtNonOption)
Parses the specified
arguments
based on the specifed Options . |
CommandLine |
parse(Options options,
java.lang.String[] arguments,
java.util.Properties properties)
Parse the arguments according to the specified options and
properties.
|
CommandLine |
parse(Options options,
java.lang.String[] arguments,
java.util.Properties properties,
boolean stopAtNonOption)
Parse the arguments according to the specified options and
properties.
|
void |
processArgs(Option opt,
java.util.ListIterator iter)
Process the argument values for the specified Option
opt using the values retrieved from the
specified iterator iter . |
private void |
processOption(java.lang.String arg,
java.util.ListIterator iter)
Process the Option specified by
arg
using the values retrieved from the specfied iterator
iter . |
private void |
processProperties(java.util.Properties properties)
Sets the values of Options using the values in
properties . |
private CommandLine cmd
private Options options
private java.util.List requiredOptions
protected abstract java.lang.String[] flatten(Options opts, java.lang.String[] arguments, boolean stopAtNonOption)
Subclasses must implement this method to reduce
the arguments
that have been passed to the parse
method.
opts
- The Options to parse the arguments by.arguments
- The arguments that have to be flattened.stopAtNonOption
- specifies whether to stop
flattening when a non option has been encounteredpublic CommandLine parse(Options options, java.lang.String[] arguments) throws ParseException
Parses the specified arguments
based on the specifed Options
.
parse
in interface CommandLineParser
options
- the Options
arguments
- the arguments
CommandLine
ParseException
- if an error occurs when parsing the
arguments.public CommandLine parse(Options options, java.lang.String[] arguments, java.util.Properties properties) throws ParseException
options
- the specified Optionsarguments
- the command line argumentsproperties
- command line option name-value pairsParseException
- if there are any problems encountered
while parsing the command line tokens.public CommandLine parse(Options options, java.lang.String[] arguments, boolean stopAtNonOption) throws ParseException
Parses the specified arguments
based on the specifed Options
.
parse
in interface CommandLineParser
options
- the Options
arguments
- the arguments
stopAtNonOption
- specifies whether to stop
interpreting the arguments when a non option has
been encountered and to add them to the CommandLines
args list.CommandLine
ParseException
- if an error occurs when parsing the
arguments.public CommandLine parse(Options options, java.lang.String[] arguments, java.util.Properties properties, boolean stopAtNonOption) throws ParseException
options
- the specified Optionsarguments
- the command line argumentsproperties
- command line option name-value pairsstopAtNonOption
- stop parsing the arguments when the first
non option is encountered.ParseException
- if there are any problems encountered
while parsing the command line tokens.private void processProperties(java.util.Properties properties)
Sets the values of Options using the values in
properties
.
properties
- The value properties to be processed.private void checkRequiredOptions() throws MissingOptionException
Throws a MissingOptionException
if all of the
required options are no present.
MissingOptionException
- if any of the required Options
are not present.public void processArgs(Option opt, java.util.ListIterator iter) throws ParseException
Process the argument values for the specified Option
opt
using the values retrieved from the
specified iterator iter
.
opt
- The current Optioniter
- The iterator over the flattened command line
Options.ParseException
- if an argument value is required
and it is has not been found.private void processOption(java.lang.String arg, java.util.ListIterator iter) throws ParseException
Process the Option specified by arg
using the values retrieved from the specfied iterator
iter
.
arg
- The String value representing an Optioniter
- The iterator over the flattened command
line arguments.ParseException
- if arg
does not
represent an Option