|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.cli.Option
Describes a single command-line option. It maintains information regarding the short-name of the option, the long-name, if any exists, a flag indicating if an argument is required for this option, and a self-documenting description of the option.
An Option is not created independantly, but is create through
an instance of Options
.
Options
,
CommandLine
Field Summary | |
static int |
UNINITIALIZED
constant that specifies the number of argument values has not been specified |
static int |
UNLIMITED_VALUES
constant that specifies the number of argument values is infinite |
Constructor Summary | |
Option(String opt,
boolean hasArg,
String description)
Creates an Option using the specified parameters. |
|
Option(String opt,
String description)
Creates an Option using the specified parameters. |
|
Option(String opt,
String longOpt,
boolean hasArg,
String description)
Creates an Option using the specified parameters. |
Method Summary | |
Object |
clone()
|
String |
getArgName()
Gets the display name for the argument value. |
int |
getArgs()
Returns the number of argument values this Option can take. |
String |
getDescription()
Retrieve the self-documenting description of this Option |
int |
getId()
Returns the id of this Option. |
String |
getLongOpt()
Retrieve the long name of this Option. |
String |
getOpt()
Retrieve the name of this Option. |
Object |
getType()
Retrieve the type of this Option. |
String |
getValue()
Returns the specified value of this Option or null if there is no value. |
String |
getValue(int index)
Returns the specified value of this Option or null if there is no value. |
String |
getValue(String defaultValue)
Returns the value/first value of this Option or the defaultValue if there is no value. |
String[] |
getValues()
Return the values of this Option as a String array or null if there are no values |
char |
getValueSeparator()
Returns the value separator character. |
List |
getValuesList()
|
boolean |
hasArg()
Query to see if this Option requires an argument |
boolean |
hasArgName()
Returns whether the display name for the argument value has been set. |
boolean |
hasArgs()
Query to see if this Option can take many values |
boolean |
hasLongOpt()
Query to see if this Option has a long name |
boolean |
hasOptionalArg()
|
boolean |
hasValueSeparator()
Return whether this Option has specified a value separator. |
boolean |
isRequired()
Query to see if this Option requires an argument |
void |
setArgName(String argName)
Sets the display name for the argument value. |
void |
setArgs(int num)
Sets the number of argument values this Option can take. |
void |
setLongOpt(String longOpt)
Sets the long name of this Option. |
void |
setOptionalArg(boolean optionalArg)
Sets whether this Option can have an optional argument. |
void |
setRequired(boolean required)
Sets whether this Option is mandatory. |
void |
setType(Object type)
Sets the type of this Option. |
void |
setValueSeparator(char sep)
Sets the value separator. |
String |
toString()
Dump state, suitable for debugging. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int UNINITIALIZED
public static final int UNLIMITED_VALUES
Constructor Detail |
public Option(String opt, String description) throws IllegalArgumentException
opt
- short representation of the optiondescription
- describes the function of the option
IllegalArgumentException
- if there are any non valid
Option characters in opt
.public Option(String opt, boolean hasArg, String description) throws IllegalArgumentException
opt
- short representation of the optionhasArg
- specifies whether the Option takes an argument or notdescription
- describes the function of the option
IllegalArgumentException
- if there are any non valid
Option characters in opt
.public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException
Creates an Option using the specified parameters.
opt
- short representation of the optionlongOpt
- the long representation of the optionhasArg
- specifies whether the Option takes an argument or notdescription
- describes the function of the option
IllegalArgumentException
- if there are any non valid
Option characters in opt
.Method Detail |
public int getId()
Returns the id of this Option. This is only set when the Option shortOpt is a single character. This is used for switch statements.
public String getOpt()
Retrieve the name of this Option.
It is this String which can be used with
CommandLine.hasOption(String opt)
and
CommandLine.getOptionValue(String opt)
to check
for existence and argument.
public Object getType()
Retrieve the type of this Option.
public void setType(Object type)
Sets the type of this Option.
type
- the type of this Optionpublic String getLongOpt()
Retrieve the long name of this Option.
public void setLongOpt(String longOpt)
Sets the long name of this Option.
longOpt
- the long name of this Optionpublic void setOptionalArg(boolean optionalArg)
Sets whether this Option can have an optional argument.
optionalArg
- specifies whether the Option can have
an optional argument.public boolean hasOptionalArg()
public boolean hasLongOpt()
Query to see if this Option has a long name
public boolean hasArg()
Query to see if this Option requires an argument
public String getDescription()
Retrieve the self-documenting description of this Option
public boolean isRequired()
Query to see if this Option requires an argument
public void setRequired(boolean required)
Sets whether this Option is mandatory.
required
- specifies whether this Option is mandatorypublic void setArgName(String argName)
Sets the display name for the argument value.
argName
- the display name for the argument value.public String getArgName()
Gets the display name for the argument value.
public boolean hasArgName()
Returns whether the display name for the argument value has been set.
public boolean hasArgs()
Query to see if this Option can take many values
public void setArgs(int num)
Sets the number of argument values this Option can take.
num
- the number of argument valuespublic void setValueSeparator(char sep)
Sets the value separator. For example if the argument value was a Java property, the value separator would be '='.
sep
- The value separator.public char getValueSeparator()
Returns the value separator character.
public boolean hasValueSeparator()
Return whether this Option has specified a value separator.
public int getArgs()
Returns the number of argument values this Option can take.
public String getValue()
null
if there is no value.
null
if there is no value.public String getValue(int index) throws IndexOutOfBoundsException
null
if there is no value.
index
- The index of the value to be returned.
null
if there is no value.
IndexOutOfBoundsException
- if index is less than 1
or greater than the number of the values for this Option.public String getValue(String defaultValue)
defaultValue
if there is no value.
defaultValue
- The value to be returned if ther
is no value.
defaultValue
if there are no values.public String[] getValues()
public List getValuesList()
public Object clone()
public String toString()
Dump state, suitable for debugging.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |