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
.
Option
public Option(String opt,
String description)
throws IllegalArgumentException
Creates an Option using the specified parameters.
opt
- short representation of the optiondescription
- describes the function of the option
Option
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
Option
public Option(String opt,
boolean hasArg,
String description)
throws IllegalArgumentException
Creates an Option using the specified parameters.
opt
- short representation of the optionhasArg
- specifies whether the Option takes an argument or notdescription
- describes the function of the option
addValue
public boolean addValue(String value)
Adds the specified value to this Option.
value
- is a/the value of this Option
clone
public Object clone()
getArgName
public String getArgName()
Gets the display name for the argument value.
- the display name for the argument value.
getArgs
public int getArgs()
Returns the number of argument values this Option can take.
- num the number of argument values
getDescription
public String getDescription()
Retrieve the self-documenting description of this Option
- The string description of this option
getId
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.
getLongOpt
public String getLongOpt()
Retrieve the long name of this Option.
- Long name of this option, or null, if there is no long name
getOpt
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.
getType
public Object getType()
Retrieve the type of this Option.
getValue
public String getValue()
- the value/first value of this Option or
null
if there are no values.
getValue
public String getValue(String defaultValue)
- the value/first value of this Option or the
defaultValue
if there are no values.
getValue
public String getValue(int index)
throws IndexOutOfBoundsException
- the specified value of this Option or
null
if there are no values.
getValueSeparator
public char getValueSeparator()
Returns the value separator character.
- the value separator character.
getValues
public String[] getValues()
- the values of this Option as a String array
or null if there are no values
getValuesList
public List getValuesList()
- the values of this Option as a List
or null if there are no values
hasArg
public boolean hasArg()
Query to see if this Option requires an argument
- boolean flag indicating if an argument is required
hasArgName
public boolean hasArgName()
Returns whether the display name for the argument value
has been set.
- if the display name for the argument value has been
set.
hasArgs
public boolean hasArgs()
Query to see if this Option can take many values
- boolean flag indicating if multiple values are allowed
hasLongOpt
public boolean hasLongOpt()
Query to see if this Option has a long name
- boolean flag indicating existence of a long name
hasOptionalArg
public boolean hasOptionalArg()
- whether this Option can have an optional argument
isRequired
public boolean isRequired()
Query to see if this Option requires an argument
- boolean flag indicating if an argument is required
isValidChar
private boolean isValidChar(char c)
Returns whether the specified character is a valid character.
c
- the character to validate
isValidOpt
private boolean isValidOpt(char c)
Returns whether the specified character is a valid Option.
c
- the option to validate
- true if
c
is a letter, ' ', '?' or '@', otherwise false.
setArgName
public void setArgName(String argName)
Sets the display name for the argument value.
argName
- the display name for the argument value.
setArgs
public void setArgs(int num)
Sets the number of argument values this Option can take.
num
- the number of argument values
setLongOpt
public void setLongOpt(String longOpt)
Sets the long name of this Option.
longOpt
- the long name of this Option
setOptionalArg
public void setOptionalArg(boolean optionalArg)
Sets whether this Option can have an optional argument.
optionalArg
- specifies whether the Option can have
an optional argument.
setRequired
public void setRequired(boolean required)
Sets whether this Option is mandatory.
required
- specifies whether this Option is mandatory
setType
public void setType(Object type)
Sets the type of this Option.
type
- the type of this Option
setValueSeparator
public 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.
toString
public String toString()
Dump state, suitable for debugging.
- Stringified form of this object
validateOption
private void validateOption(String opt)
throws IllegalArgumentException
Validates whether
opt
is a permissable Option
shortOpt. The rules that specify if the
opt
is valid are:
opt
is not NULL- a single character
opt
that is either
' '(special case), '?', '@' or a letter - a multi character
opt
that only contains
letters.
opt
- The option string to validate