Package org.apache.commons.cli
Class Parser
- java.lang.Object
-
- org.apache.commons.cli.Parser
-
- All Implemented Interfaces:
CommandLineParser
- Direct Known Subclasses:
BasicParser
,GnuParser
,PosixParser
public abstract class Parser extends java.lang.Object implements CommandLineParser
Parser
createsCommandLine
s.- Version:
- $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
- Author:
- John Keyes (john at integralsource.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected CommandLine
cmd
commandline instance
-
Constructor Summary
Constructors Constructor Description Parser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkRequiredOptions()
Throws aMissingOptionException
if all of the required options are not present.protected abstract java.lang.String[]
flatten(Options opts, java.lang.String[] arguments, boolean stopAtNonOption)
Subclasses must implement this method to reduce thearguments
that have been passed to the parse method.protected Options
getOptions()
protected java.util.List
getRequiredOptions()
CommandLine
parse(Options options, java.lang.String[] arguments)
Parses the specifiedarguments
based on the specifedOptions
.CommandLine
parse(Options options, java.lang.String[] arguments, boolean stopAtNonOption)
Parses the specifiedarguments
based on the specifedOptions
.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 Optionopt
using the values retrieved from the specified iteratoriter
.protected void
processOption(java.lang.String arg, java.util.ListIterator iter)
Process the Option specified byarg
using the values retrieved from the specfied iteratoriter
.protected void
processProperties(java.util.Properties properties)
Sets the values of Options using the values inproperties
.protected void
setOptions(Options options)
-
-
-
Field Detail
-
cmd
protected CommandLine cmd
commandline instance
-
-
Constructor Detail
-
Parser
public Parser()
-
-
Method Detail
-
setOptions
protected void setOptions(Options options)
-
getOptions
protected Options getOptions()
-
getRequiredOptions
protected java.util.List getRequiredOptions()
-
flatten
protected abstract java.lang.String[] flatten(Options opts, java.lang.String[] arguments, boolean stopAtNonOption)
Subclasses must implement this method to reduce thearguments
that have been passed to the parse method.- Parameters:
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 encountered- Returns:
- a String array of the flattened arguments
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments) throws ParseException
Parses the specifiedarguments
based on the specifedOptions
.- Specified by:
parse
in interfaceCommandLineParser
- Parameters:
options
- theOptions
arguments
- thearguments
- Returns:
- the
CommandLine
- Throws:
ParseException
- if an error occurs when parsing the arguments.
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments, java.util.Properties properties) throws ParseException
Parse the arguments according to the specified options and properties.- Parameters:
options
- the specified Optionsarguments
- the command line argumentsproperties
- command line option name-value pairs- Returns:
- the list of atomic option and value tokens
- Throws:
ParseException
- if there are any problems encountered while parsing the command line tokens.- Since:
- 1.1
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments, boolean stopAtNonOption) throws ParseException
Parses the specifiedarguments
based on the specifedOptions
.- Specified by:
parse
in interfaceCommandLineParser
- Parameters:
options
- theOptions
arguments
- thearguments
stopAtNonOption
- specifies whether to stop interpreting the arguments when a non option has been encountered and to add them to the CommandLines args list.- Returns:
- the
CommandLine
- Throws:
ParseException
- if an error occurs when parsing the arguments.
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments, java.util.Properties properties, boolean stopAtNonOption) throws ParseException
Parse the arguments according to the specified options and properties.- Parameters:
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.- Returns:
- the list of atomic option and value tokens
- Throws:
ParseException
- if there are any problems encountered while parsing the command line tokens.- Since:
- 1.1
-
processProperties
protected void processProperties(java.util.Properties properties)
Sets the values of Options using the values inproperties
.- Parameters:
properties
- The value properties to be processed.
-
checkRequiredOptions
protected void checkRequiredOptions() throws MissingOptionException
Throws aMissingOptionException
if all of the required options are not present.- Throws:
MissingOptionException
- if any of the required Options are not present.
-
processArgs
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 iteratoriter
.- Parameters:
opt
- The current Optioniter
- The iterator over the flattened command line Options.- Throws:
ParseException
- if an argument value is required and it is has not been found.
-
processOption
protected void processOption(java.lang.String arg, java.util.ListIterator iter) throws ParseException
Process the Option specified byarg
using the values retrieved from the specfied iteratoriter
.- Parameters:
arg
- The String value representing an Optioniter
- The iterator over the flattened command line arguments.- Throws:
ParseException
- ifarg
does not represent an Option
-
-