public class CommandLine
extends java.lang.Object
implements java.io.Serializable
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.
Modifier and Type | Class and Description |
---|---|
static class |
CommandLine.Builder
A nested builder class to create
CommandLine instance using descriptive methods. |
Modifier | Constructor and Description |
---|---|
protected |
CommandLine()
Creates a command line.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addArg(java.lang.String arg)
Add left-over unrecognized option/argument.
|
protected void |
addOption(Option opt)
Add an option to the command line.
|
java.util.List<java.lang.String> |
getArgList()
Retrieve any left-over non-recognized options and arguments
|
java.lang.String[] |
getArgs()
Retrieve any left-over non-recognized options and arguments
|
java.lang.Object |
getOptionObject(char opt)
Deprecated.
due to System.err message. Instead use getParsedOptionValue(char)
|
java.lang.Object |
getOptionObject(java.lang.String opt)
Deprecated.
due to System.err message. Instead use getParsedOptionValue(String)
|
java.util.Properties |
getOptionProperties(Option option)
Retrieve the map of values associated to the option.
|
java.util.Properties |
getOptionProperties(java.lang.String opt)
Retrieve the map of values associated to the option.
|
Option[] |
getOptions()
Gets an array of the processed
Option s. |
java.lang.String |
getOptionValue(char opt)
Retrieve the first argument, if any, of this option.
|
java.lang.String |
getOptionValue(char opt,
java.lang.String defaultValue)
Retrieve the argument, if any, of an option.
|
java.lang.String |
getOptionValue(Option option)
Retrieve the first argument, if any, of this option.
|
java.lang.String |
getOptionValue(Option option,
java.lang.String defaultValue)
Retrieve the first argument, if any, of an option.
|
java.lang.String |
getOptionValue(java.lang.String opt)
Retrieve the first argument, if any, of this option.
|
java.lang.String |
getOptionValue(java.lang.String opt,
java.lang.String defaultValue)
Retrieve the first argument, if any, of an option.
|
java.lang.String[] |
getOptionValues(char opt)
Retrieves the array of values, if any, of an option.
|
java.lang.String[] |
getOptionValues(Option option)
Retrieves the array of values, if any, of an option.
|
java.lang.String[] |
getOptionValues(java.lang.String opt)
Retrieves the array of values, if any, of an option.
|
java.lang.Object |
getParsedOptionValue(char opt)
Return a version of this
Option converted to a particular type. |
java.lang.Object |
getParsedOptionValue(Option option)
Return a version of this
Option converted to a particular type. |
java.lang.Object |
getParsedOptionValue(java.lang.String opt)
Return a version of this
Option converted to a particular type. |
boolean |
hasOption(char opt)
Tests to see if an option has been set.
|
boolean |
hasOption(Option opt)
Tests to see if an option has been set.
|
boolean |
hasOption(java.lang.String opt)
Tests to see if an option has been set.
|
java.util.Iterator<Option> |
iterator()
Returns an iterator over the Option members of CommandLine.
|
protected void addArg(java.lang.String arg)
arg
- the unrecognized option/argument.protected void addOption(Option opt)
opt
- the processed option.public java.util.List<java.lang.String> getArgList()
List
.public java.lang.String[] getArgs()
@Deprecated public java.lang.Object getOptionObject(char opt)
Object
type of this Option
.opt
- the name of the option.@Deprecated public java.lang.Object getOptionObject(java.lang.String opt)
Object
type of this Option
.opt
- the name of the option.Option
.public java.util.Properties getOptionProperties(Option option)
-Dparam1=value1
-Dparam2=value2
. The first argument of the option is the key, and the 2nd argument is the value. If the option
has only one argument (-Dfoo
) it is considered as a boolean flag and the value is "true"
.option
- name of the option.null
even if the option doesn't exists.public java.util.Properties getOptionProperties(java.lang.String opt)
-Dparam1=value1
-Dparam2=value2
. The first argument of the option is the key, and the 2nd argument is the value. If the option
has only one argument (-Dfoo
) it is considered as a boolean flag and the value is "true"
.opt
- name of the option.null
even if the option doesn't exists.public Option[] getOptions()
Option
s.Option
s.public java.lang.String getOptionValue(char opt)
opt
- the character name of the option.public java.lang.String getOptionValue(char opt, java.lang.String defaultValue)
opt
- character name of the optiondefaultValue
- is the default value to be returned if the option is not specified.defaultValue
.public java.lang.String getOptionValue(Option option)
option
- the name of the option.public java.lang.String getOptionValue(Option option, java.lang.String defaultValue)
option
- name of the option.defaultValue
- is the default value to be returned if the option is not specified.defaultValue
.public java.lang.String getOptionValue(java.lang.String opt)
opt
- the name of the option.public java.lang.String getOptionValue(java.lang.String opt, java.lang.String defaultValue)
opt
- name of the option.defaultValue
- is the default value to be returned if the option is not specified.defaultValue
.public java.lang.String[] getOptionValues(char opt)
opt
- character name of the option.public java.lang.String[] getOptionValues(Option option)
option
- string name of the option.public java.lang.String[] getOptionValues(java.lang.String opt)
opt
- string name of the option.public java.lang.Object getParsedOptionValue(char opt) throws ParseException
Option
converted to a particular type.opt
- the name of the option.ParseException
- if there are problems turning the option value into the desired typePatternOptionBuilder
public java.lang.Object getParsedOptionValue(Option option) throws ParseException
Option
converted to a particular type.option
- the name of the option.ParseException
- if there are problems turning the option value into the desired typePatternOptionBuilder
public java.lang.Object getParsedOptionValue(java.lang.String opt) throws ParseException
Option
converted to a particular type.opt
- the name of the option.ParseException
- if there are problems turning the option value into the desired typePatternOptionBuilder
public boolean hasOption(char opt)
opt
- character name of the option.public boolean hasOption(Option opt)
opt
- the option to check.public boolean hasOption(java.lang.String opt)
opt
- Short name of the option.public java.util.Iterator<Option> iterator()
Iterator
over the processed Option
members of this CommandLine
.