org.apache.commons.cli
Class CommandLine
java.lang.Object
org.apache.commons.cli.CommandLine
public class CommandLine
extends java.lang.Object
Represents list of arguments parsed against
a
Options
descriptor.
It allows querying of a boolean
hasOption(String opt)
,
in addition to retrieving the
getOptionValue(String opt)
for options requiring arguments.
Additionally, any left-over or unrecognized arguments,
are available for further processing.
- bob mcwhirter (bob @ werken.com)
- James Strachan
- John Keyes (john at integralsource.com)
private List | args - the unrecognised options/arguments
|
private Set | options - the processed options
|
(package private) void | addArg(String arg) - Add left-over unrecognized option/argument.
|
(package private) void | addOption(Option opt) - Add an option to the command line.
|
List | getArgList() - Retrieve any left-over non-recognized options and arguments
|
String[] | getArgs() - Retrieve any left-over non-recognized options and arguments
|
Object | getOptionObject(String opt) - Return the
Object type of this Option .
|
Object | getOptionObject(char opt) - Return the
Object type of this Option .
|
String | getOptionValue(String opt) - Retrieve the argument, if any, of this option.
|
String | getOptionValue(String opt, String defaultValue) - Retrieve the argument, if any, of an option.
|
String | getOptionValue(char opt) - Retrieve the argument, if any, of this option.
|
String | getOptionValue(char opt, String defaultValue) - Retrieve the argument, if any, of an option.
|
String[] | getOptionValues(String opt) - Retrieves the array of values, if any, of an option.
|
String[] | getOptionValues(char opt) - Retrieves the array of values, if any, of an option.
|
Option[] | getOptions() - Returns an array of the processed
Option s.
|
boolean | hasOption(String opt) - Query to see if an option has been set.
|
boolean | hasOption(char opt) - Query to see if an option has been set.
|
Iterator | iterator() - Returns an iterator over the Option members of CommandLine.
|
private Option | resolveOption(String opt) - Retrieves the option object given the long or short option as a String
|
args
private List args
the unrecognised options/arguments
options
private Set options
the processed options
CommandLine
(package private) CommandLine()
Creates a command line.
addArg
(package private) void addArg(String arg)
Add left-over unrecognized option/argument.
arg
- the unrecognised option/argument.
addOption
(package private) void addOption(Option opt)
Add an option to the command line. The values of
the option are stored.
opt
- the processed option
getArgList
public List getArgList()
Retrieve any left-over non-recognized options and arguments
- remaining items passed in but not parsed as a
List
.
getArgs
public String[] getArgs()
Retrieve any left-over non-recognized options and arguments
- remaining items passed in but not parsed as an array
getOptionObject
public Object getOptionObject(String opt)
Return the Object
type of this Option
.
opt
- the name of the option
getOptionObject
public Object getOptionObject(char opt)
Return the Object
type of this Option
.
opt
- the name of the option
getOptionValue
public String getOptionValue(String opt)
Retrieve the argument, if any, of this option.
opt
- the name of the option
- Value of the argument if option is set, and has an argument,
otherwise null.
getOptionValue
public String getOptionValue(String opt,
String defaultValue)
Retrieve the argument, if any, of an option.
opt
- name of the optiondefaultValue
- is the default value to be returned if the option
is not specified
- Value of the argument if option is set, and has an argument,
otherwise
defaultValue
.
getOptionValue
public String getOptionValue(char opt)
Retrieve the argument, if any, of this option.
opt
- the character name of the option
- Value of the argument if option is set, and has an argument,
otherwise null.
getOptionValue
public String getOptionValue(char opt,
String defaultValue)
Retrieve the argument, if any, of an option.
opt
- character name of the optiondefaultValue
- is the default value to be returned if the option
is not specified
- Value of the argument if option is set, and has an argument,
otherwise
defaultValue
.
getOptionValues
public String[] getOptionValues(String opt)
Retrieves the array of values, if any, of an option.
opt
- string name of the option
- Values of the argument if option is set, and has an argument,
otherwise null.
getOptionValues
public String[] getOptionValues(char opt)
Retrieves the array of values, if any, of an option.
opt
- character name of the option
- Values of the argument if option is set, and has an argument,
otherwise null.
getOptions
public Option[] getOptions()
Returns an array of the processed
Option
s.
- an array of the processed
Option
s.
hasOption
public boolean hasOption(String opt)
Query to see if an option has been set.
opt
- Short name of the option
- true if set, false if not
hasOption
public boolean hasOption(char opt)
Query to see if an option has been set.
opt
- character name of the option
- true if set, false if not
iterator
public Iterator iterator()
Returns an iterator over the Option members of CommandLine.
resolveOption
private Option resolveOption(String opt)
Retrieves the option object given the long or short option as a String
opt
- short or long name of the option