org.apache.commons.cli
public class Option extends Object implements Cloneable
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.
Version: $Revision: 551821 $
See Also: Options
Field Summary | |
---|---|
String | argName argName specifies the name of the argument for this option |
String | description description of the option |
boolean | hasArg hasArg specifies whether this option has an associated argument |
String | longOpt longOpt is the long representation of the option |
int | numberOfArgs
numberOfArgs specifies the number of argument values this option
can have |
String | opt opt the name of the option |
boolean | optionalArg specifies whether the argument value of this Option is optional |
boolean | required required specifies whether this option is required to be present |
Object | type the type of this Option |
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 |
ArrayList | values the list of argument values * |
char | valuesep the character that is the value separator |
Constructor Summary | |
---|---|
Option(String opt, String description)
Creates an Option using the specified parameters.
| |
Option(String opt, boolean hasArg, 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 | |
---|---|
void | add(String value)
Add the value to this Option.
|
boolean | addValue(String value)
This method is not intended to be used. |
void | addValueForProcessing(String value)
Adds the specified value to this Option.
|
void | clearValues() Clear the Option values. |
Object | clone()
A rather odd clone method - due to incorrect code in 1.0 it is public
and in 1.1 rather than throwing a CloneNotSupportedException it throws
a RuntimeException so as to maintain backwards compat at the API level.
|
boolean | equals(Object o) |
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 | getKey()
Returns the 'unique' Option identifier.
|
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
|
List | getValuesList() |
char | getValueSeparator()
Returns the value separator character.
|
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.
|
int | hashCode() |
boolean | hasLongOpt()
Query to see if this Option has a long name
|
boolean | hasNoValues()
Returns whether this Option has any values.
|
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 | processValue(String value)
Processes the value. |
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 | setDescription(String description)
Sets the self-documenting description of this Option
|
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.
|
Parameters: opt short representation of the option description describes the function of the option
Throws: IllegalArgumentException if there are any non valid
Option characters in opt
.
Parameters: opt short representation of the option hasArg specifies whether the Option takes an argument or not description describes the function of the option
Throws: IllegalArgumentException if there are any non valid
Option characters in opt
.
Parameters: opt short representation of the option longOpt the long representation of the option hasArg specifies whether the Option takes an argument or not description describes the function of the option
Throws: IllegalArgumentException if there are any non valid
Option characters in opt
.
Parameters: value The value to be added to this Option
Since: 1.0.1
Deprecated:
This method is not intended to be used. It was a piece of internal API that was made public in 1.0. It currently throws an UnsupportedOperationException.Throws: UnsupportedOperationException
Parameters: value is a/the value of this Option
Clear the Option values. After a parse is complete, these are left with data in them and they need clearing if another parse is done.
See: CLI-71Throws: RuntimeException
Returns: the display name for the argument value.
Returns: num the number of argument values
Returns: The string description of this option
Returns: the id of this Option
Returns: the 'unique' Option identifier
Returns: Long name of this option, or null, if there is no long name
Returns: The name of this option
Returns: The type of this option
null
if there is no value.
Returns: the value/first value of this Option or
null
if there is no value.
null
if there is no value.
Parameters: index The index of the value to be returned.
Returns: the specified value of this Option or
null
if there is no value.
Throws: IndexOutOfBoundsException if index is less than 1 or greater than the number of the values for this Option.
defaultValue
if there is no value.
Parameters: defaultValue The value to be returned if ther is no value.
Returns: the value/first value of this Option or the
defaultValue
if there are no values.
Returns: the values of this Option as a String array or null if there are no values
Returns: the values of this Option as a List or null if there are no values
Returns: the value separator character.
Returns: boolean flag indicating if an argument is required
Returns: if the display name for the argument value has been set.
Returns: boolean flag indicating if multiple values are allowed
Returns: boolean flag indicating existence of a long name
Returns: whether this Option has any values.
Returns: whether this Option can have an optional argument
Returns: whether this Option has specified a value separator.
Returns: boolean flag indicating if an argument is required
Parameters: value The String to be processed.
Since: 1.0.1
Parameters: argName the display name for the argument value.
Parameters: num the number of argument values
Parameters: description The description of this option
Parameters: longOpt the long name of this Option
Parameters: optionalArg specifies whether the Option can have an optional argument.
Parameters: required specifies whether this Option is mandatory
Parameters: type the type of this Option
Parameters: sep The value separator.
Returns: Stringified form of this object