|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcmdline.AbstractParameter
jcmdline.BooleanParam
Encapsulate a boolean command line parameter. This parameter defaults to "false" if not set by the user.
Sample usage:
BooleanParam deleteOpt = new BooleanParam("delete", "delete original file"); FileParam outfileOpt = new FileParam("outfile", "the outfile file - defaults to stdout", FileParam.DOESNT_EXIST); FileParam infileArg = new FileParam("infile", "the input file - defaults to stdin", FileParam.IS_READABLE & FileParam.IS_FILE); CmdLineHandler clh = new DefaultCmdLineHandler( "filter", "filters files for obscenities", new Parameter[] { deleteOpt, outfileOpt }, new Parameter[] { infileArg } ); clh.parse(args); if (deleteOpt.isTrue()) { .... }
CmdLineParser
Field Summary |
Fields inherited from class jcmdline.AbstractParameter |
acceptableValues, desc, hidden, ignoreRequired, multiValued, optional, optionLabel, set, tag, values |
Fields inherited from interface jcmdline.Parameter |
HIDDEN, MULTI_VALUED, OPTIONAL, PUBLIC, REQUIRED, SINGLE_VALUED |
Constructor Summary | |
BooleanParam(java.lang.String tag,
java.lang.String desc)
constructor - creates a public boolean parameter |
|
BooleanParam(java.lang.String tag,
java.lang.String desc,
boolean hidden)
constructor - creates a boolean parameter that is public or hidden, as specified |
Method Summary | |
void |
addValue(java.lang.String value)
Sets the specified string as a value for this BooleanParam. |
java.lang.String |
getDefaultValue()
Gets the default value of this Parameter when used as a command line option, and specified just by its tag. |
boolean |
isTrue()
Returns the value of the parameter as a boolean. |
void |
validateValue(java.lang.String value)
Verifies that value is either "true" or "false" -
called by add/setValue(s)(). |
Methods inherited from class jcmdline.AbstractParameter |
getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setAcceptableValues, setAcceptableValues, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValues |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BooleanParam(java.lang.String tag, java.lang.String desc)
tag
- a unique identifier for this parameterdesc
- a description of the parameter, suitable for display
in a usage statement
java.lang.IllegalArgumentException
- if any specified
parameter is invalid.setTag()
,
setDesc()
public BooleanParam(java.lang.String tag, java.lang.String desc, boolean hidden)
tag
- a unique identifier for this parameterdesc
- a description of the parameter, suitable for display
in a usage statementhidden
- HIDDEN
if parameter is
not to be listed in the usage,
PUBLIC
otherwise.
java.lang.IllegalArgumentException
- if any specified
parameter is invalid.setTag()
,
setDesc()
,
HIDDEN
,
PUBLIC
Method Detail |
public void addValue(java.lang.String value) throws CmdLineException
addValue
in interface Parameter
addValue
in class AbstractParameter
value
- the value to be set
CmdLineException
- if validateValue()
detects a problem.public java.lang.String getDefaultValue()
getDefaultValue
in interface OptionTakesNoValue
OptionTakesNoValue
public boolean isTrue()
public void validateValue(java.lang.String value) throws CmdLineException
value
is either "true" or "false" -
called by add/setValue(s)().
validateValue
in interface Parameter
validateValue
in class AbstractParameter
value
- the value to be validated
CmdLineException
- if value
is not valid.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |