public class Option
extends java.lang.Object
Constructor and Description |
---|
Option(java.lang.String opt,
java.lang.String name,
java.lang.String usage,
int cmin,
int cmax)
creates a command line option.
|
Option(java.lang.String opt,
java.lang.String name,
java.lang.String usage,
int cmin,
int cmax,
java.lang.Object[] defalt)
creates a command line option with default.
|
Modifier and Type | Method and Description |
---|---|
boolean |
available()
returns true if the option was found on the command line or has
default values.
|
java.lang.Object |
getValue()
returns the first element of the vector returned by
getValues . |
java.util.List<java.lang.Object> |
getValues()
returns the arguments found on the command line or set as a
default for this option.
|
Option |
required()
converts the option into a required command line argument and
Commandline.parse() will check this. |
Option |
setDefault(java.lang.String[] defalt)
defines default values for this
Option . |
public Option(java.lang.String opt, java.lang.String name, java.lang.String usage, int cmin, int cmax)
creates a command line option.
opt
- is the option string introducing this option on the
command line and normally starts with a dash,
i.e. "-v"
.name
- is a symbolic name for the variable
initialized by the option, only used in usage
output.usage
- is a one liner describing the intend of this optioncmin
- is the minimum number of command line arguments for
this optioncmax
- is the maximum number of command line arguments for
this optionpublic Option(java.lang.String opt, java.lang.String name, java.lang.String usage, int cmin, int cmax, java.lang.Object[] defalt) throws CommandlineException
creates a command line option with default. This constructor first calls
the constructor without default and then calls setDefalt(java.lang.Object[])
to set
the default values.
CommandlineException
- if the number of default values is wrong or if they are not of
type String.public final Option setDefault(java.lang.String[] defalt) throws CommandlineException
defines default values for this Option
.
this
CommandlineException
- if the value does not conform to check(java.lang.Object)
or if there arejava.lang.IllegalArgumentException
- if defalt
contains too many valuespublic Option required()
converts the option into a required command line argument and
Commandline.parse()
will check this.
this
public boolean available()
public java.util.List<java.lang.Object> getValues()
null
. The elements
of the resulting vector are of type String
or
whatever was passed in as the defalt
parameter of
the constructor. For subclasses of Option
, different
types may be returned.public java.lang.Object getValue()
getValues
. This is a convenience method normally to
be used only for options with exactly one parameter. If the
option is indeed "optional", a call to available()
should preceed this call.