Modifier and Type | Method and Description |
---|---|
ArgumentImpl |
action(ArgumentAction action)
Sets the action to be taken when this argument is encountered at the
command line.
|
ArgumentImpl |
choices(ArgumentChoice choice)
Sets
ArgumentChoice object which inspects value so that it
fulfills its criteria. |
<E> ArgumentImpl |
choices(Collection<E> values)
Sets a collection of the allowable values for the argument.
|
<E> ArgumentImpl |
choices(E... values)
Sets a collection of the allowable values for the argument.
|
Object |
convert(ArgumentParserImpl parser,
String value) |
ArgumentImpl |
dest(String dest)
The name of the attribute to be added.
|
ArgumentAction |
getAction() |
Object |
getConst()
Returns const value.
|
Object |
getDefault()
Returns default value.
|
FeatureControl |
getDefaultControl()
Returns default control.
|
String |
getDest()
Returns dest value.
|
String |
getHelp() |
FeatureControl |
getHelpControl()
Returns help control.
|
String[] |
getMetavar() |
String |
getName() |
ArgumentImpl |
help(FeatureControl ctrl)
Sets special value to control help message handling.
|
ArgumentImpl |
help(String help)
Sets the brief description of what the argument does.
|
boolean |
isRequired() |
ArgumentImpl |
metavar(String... metavar)
Set the name for the argument in usage messages.
|
ArgumentImpl |
nargs(int n)
Sets the number of command line arguments that should be consumed.
|
ArgumentImpl |
nargs(String n)
Sets the number of command line arguments that should be consumed.
|
void |
printHelp(PrintWriter writer,
boolean defaultHelp,
TextWidthCounter textWidthCounter,
int width) |
ArgumentImpl |
required(boolean required)
If
true is given, this named argument must be specified in
command line otherwise error will be issued. |
void |
run(ArgumentParserImpl parser,
Map<String,Object> res,
String flag,
Object value) |
<E> ArgumentImpl |
setConst(E... values)
Sets list of constant values that are not read from the command line but
are required for the various actions.
|
ArgumentImpl |
setConst(Object value)
Sets constant values that are not read from the command line but are
required for the various actions.
|
<E> ArgumentImpl |
setDefault(E... values)
Sets list of values which should be used if the command line argument is
not present.
|
ArgumentImpl |
setDefault(FeatureControl ctrl)
Sets special value to control default value handling.
|
ArgumentImpl |
setDefault(Object value)
Sets value which should be used if the command line argument is not
present.
|
String |
textualName()
Returns textual representation of the argument name.
|
<T> ArgumentImpl |
type(ArgumentType<T> type)
Sets
ArgumentType object which converts command line argument to
appropriate type. |
<T> ArgumentImpl |
type(Class<T> type)
Sets the type which the command line argument should be converted to.
|
public String textualName()
Argument
Returns textual representation of the argument name.
For named arguments, this method returns the first argument given in
ArgumentContainer.addArgument(String...)
. For positional arguments,
this method returns the flags joined with "/", e.g. -f/--foo
.
textualName
in interface Argument
public void printHelp(PrintWriter writer, boolean defaultHelp, TextWidthCounter textWidthCounter, int width)
public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException
ArgumentParserException
public ArgumentImpl nargs(int n)
Argument
Sets the number of command line arguments that should be consumed.
Don't give this method '*'
, '+'
or '?'
. They are
converted to int
value and it is not what you expect. For these
strings, use Argument.nargs(String)
.
public ArgumentImpl nargs(String n)
Argument
Sets the number of command line arguments that should be consumed.
This method takes one of following string: "*"
, "+"
and
"?"
. If "*"
is given, All command line arguments present
are gathered into a List
. If "+"
is given, just
like "*"
, all command line arguments present are gathered into a
List
. Additionally, an error message will be generated
if there wasn't at least one command line argument present. If
"?"
is given, one argument will be consumed from the command line
if possible, and produced as a single item. If no command line argument
is present, the value from Argument.setDefault(Object)
will be produced.
Note that for named arguments, there is an additional case - the
option string is present but not followed by a command line argument. In
this case the value from Argument.setConst(Object)
will be produced.
public ArgumentImpl setConst(Object value)
Argument
Sets constant values that are not read from the command line but are required for the various actions.
The const value defaults to null
.
public <E> ArgumentImpl setConst(E... values)
Argument
Sets list of constant values that are not read from the command line but are required for the various actions.
The given values
will be converted to List
. The const
value defaults to null
. If you want to set non-List item, use
Argument.setConst(Object)
.
public ArgumentImpl setDefault(Object value)
Argument
Sets value which should be used if the command line argument is not present.
The default value defaults to null
.
setDefault
in interface Argument
value
- The default valuepublic <E> ArgumentImpl setDefault(E... values)
Argument
Sets list of values which should be used if the command line argument is not present.
The default value defaults to null
. The given values
will
be converted to List
. If you want to set non-List item, use
Argument.setDefault(Object)
.
setDefault
in interface Argument
values
- The default valuespublic ArgumentImpl setDefault(FeatureControl ctrl)
Argument
Sets special value to control default value handling.
Currently, only FeatureControl.SUPPRESS
is available. If it is
given, default value is not add as a attribute.
setDefault
in interface Argument
ctrl
- The special value to control default value handling.public <T> ArgumentImpl type(Class<T> type)
Argument
Sets the type which the command line argument should be converted to.
By default, type is String, which means no conversion is made. The type must have a constructor which takes one String argument.
As a convenience, if one of following primitive types (boolean.class, byte.class, short.class, int.class, long.class, float.class and double.class) is specified, it is converted to its wrapped type counterpart. For example, if int.class is given, it is silently converted to Integer.class.
public <T> ArgumentImpl type(ArgumentType<T> type)
Argument
Sets ArgumentType
object which converts command line argument to
appropriate type.
This would be useful if you need to convert the command line argument into a type which does not have a constructor with one String argument.
type
in interface Argument
type
- The ArgumentType
objectpublic ArgumentImpl required(boolean required)
Argument
If true
is given, this named argument must be specified in
command line otherwise error will be issued.
The default value is false
. This object is a positional argument,
this property is ignored.
public ArgumentImpl action(ArgumentAction action)
Argument
action
in interface Argument
action
- ArgumentAction
objectpublic ArgumentImpl choices(ArgumentChoice choice)
Argument
Sets ArgumentChoice
object which inspects value so that it
fulfills its criteria.
This method is useful if more complex inspection is necessary than basic
Argument.choices(Object...)
.
choices
in interface Argument
choice
- ArgumentChoice
object.public <E> ArgumentImpl choices(Collection<E> values)
Argument
public <E> ArgumentImpl choices(E... values)
Argument
public ArgumentImpl dest(String dest)
Argument
The name of the attribute to be added.
The default value is For positional arguments, The default value is
normally supplied as the first argument to
ArgumentParser.parseArgs(String[])
. For named arguments,
ArgumentParser
generates the default value of dest
by
taking the first long option string and stripping away the initial
--
string. If no long option strings were supplied, dest
will be derived from the first short option string by stripping the
initial -
character. Any internal -
characters will be
converted to _
.
public ArgumentImpl metavar(String... metavar)
Argument
public ArgumentImpl help(String help)
Argument
public ArgumentImpl help(FeatureControl ctrl)
Argument
Sets special value to control help message handling.
Currently, only FeatureControl.SUPPRESS
is available. If it is
given, the help entry for this option is not displayed in the help
message.
public void run(ArgumentParserImpl parser, Map<String,Object> res, String flag, Object value) throws ArgumentParserException
ArgumentParserException
public Object getDefault()
Argument
getDefault
in interface Argument
public FeatureControl getDefaultControl()
Argument
getDefaultControl
in interface Argument
public FeatureControl getHelpControl()
Argument
getHelpControl
in interface Argument
public String getName()
public boolean isRequired()
public String[] getMetavar()
public ArgumentAction getAction()
public String getHelp()
Copyright © 2012–2017. All rights reserved.