public class DefaultParser extends Object implements CommandLineParser
Modifier and Type | Field and Description |
---|---|
protected CommandLine |
cmd
The command-line instance.
|
protected Option |
currentOption
The last option parsed.
|
protected String |
currentToken
The token currently processed.
|
protected List |
expectedOpts
The required options and groups expected to be found when parsing the command line.
|
protected Options |
options
The current options.
|
protected boolean |
skipParsing
Flag indicating if tokens should no longer be analysed and simply added as arguments of the command line.
|
protected boolean |
stopAtNonOption
Flag indicating how unrecognized tokens are handled.
|
Constructor and Description |
---|
DefaultParser() |
Modifier and Type | Method and Description |
---|---|
protected void |
handleConcatenatedOptions(String token)
Breaks
token into its constituent parts
using the following algorithm. |
CommandLine |
parse(Options options,
String[] arguments)
Parse the arguments according to the specified options.
|
CommandLine |
parse(Options options,
String[] arguments,
boolean stopAtNonOption)
Parse the arguments according to the specified options.
|
CommandLine |
parse(Options options,
String[] arguments,
Properties properties)
Parse the arguments according to the specified options and properties.
|
CommandLine |
parse(Options options,
String[] arguments,
Properties properties,
boolean stopAtNonOption)
Parse the arguments according to the specified options and properties.
|
protected CommandLine cmd
protected boolean stopAtNonOption
protected String currentToken
protected Option currentOption
protected boolean skipParsing
protected List expectedOpts
public DefaultParser()
public CommandLine parse(Options options, String[] arguments) throws ParseException
CommandLineParser
parse
in interface CommandLineParser
options
- the specified Optionsarguments
- the command line argumentsParseException
- if there are any problems encountered
while parsing the command line tokens.public CommandLine parse(Options options, String[] arguments, 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, String[] arguments, boolean stopAtNonOption) throws ParseException
CommandLineParser
parse
in interface CommandLineParser
options
- the specified Optionsarguments
- the command line argumentsstopAtNonOption
- if true an unrecognized argument stops
the parsing and the remaining arguments are added to the
CommandLine
s args list. If false an unrecognized
argument triggers a ParseException.ParseException
- if there are any problems encountered
while parsing the command line tokens.public CommandLine parse(Options options, String[] arguments, Properties properties, boolean stopAtNonOption) throws ParseException
options
- the specified Optionsarguments
- the command line argumentsproperties
- command line option name-value pairsstopAtNonOption
- if true an unrecognized argument stops
the parsing and the remaining arguments are added to the
CommandLine
s args list. If false an unrecognized
argument triggers a ParseException.ParseException
- if there are any problems encountered
while parsing the command line tokens.protected void handleConcatenatedOptions(String token) throws ParseException
token
into its constituent parts
using the following algorithm.
Option
exists with that id.Option
does exist then add that character
prepended with "-" to the list of processed tokens.Option
can have an argument value and there
are remaining characters in the token then add the remaining
characters as a token to the list of processed tokens.Option
does NOT exist AND
stopAtNonOption
IS set then add the special token
"--" followed by the remaining characters and also
the remaining tokens directly to the processed tokens list.Option
does NOT exist AND
stopAtNonOption
IS NOT set then add that
character prepended with "-".token
- The current token to be burst
at the first non-Option encountered.ParseException
- if there are any problems encountered
while parsing the command line token.Copyright © 2002–2015 The Apache Software Foundation. All rights reserved.