Interface Argument
- All Known Implementing Classes:
ArgumentImpl
ArgumentParser
object.-
Method Summary
Modifier and TypeMethodDescriptionaction
(ArgumentAction action) Sets the action to be taken when this argument is encountered at the command line.<E> Argument
choices
(E... values) Sets a collection of the allowable values for the argument.<E> Argument
choices
(Collection<E> values) Sets a collection of the allowable values for the argument.choices
(ArgumentChoice choice) SetsArgumentChoice
object which inspects value so that it fulfills its criteria.The name of the attribute to be added.getConst()
Returns const value.Returns default value.Returns default control.getDest()
Returns dest value.Returns help control.Sets the brief description of what the argument does.help
(FeatureControl ctrl) Sets special value to control help message handling.Set the name for the argument in usage messages.nargs
(int n) Sets the number of command line arguments that should be consumed.Sets the number of command line arguments that should be consumed.required
(boolean required) Iftrue
is given, this optional argument must be specified in command line otherwise error will be issued.<E> Argument
setConst
(E... values) Sets list of constant values that are not read from the command line but are required for the various actions.Sets constant values that are not read from the command line but are required for the various actions.<E> Argument
setDefault
(E... values) Sets list of values which should be used if the command line argument is not present.setDefault
(Object value) Sets value which should be used if the command line argument is not present.setDefault
(FeatureControl ctrl) Sets special value to control default value handling.Returns textual representation of the argument name.<T> Argument
Sets the type which the command line argument should be converted to.<T> Argument
type
(ArgumentType<T> type) SetsArgumentType
object which converts command line argument to appropriate type.
-
Method Details
-
nargs
Sets the number of command line arguments that should be consumed.
Don't give this method
'*'
,'+'
or'?'
. They are converted toint
value and it is not what you expect. For these strings, usenargs(String)
.- Parameters:
n
- A positive integer- Returns:
- this
-
nargs
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 aList
. If"+"
is given, just like"*"
, all command line arguments present are gathered into aList
. 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 fromsetDefault(Object)
will be produced. Note that for optional arguments, there is an additional case - the option string is present but not followed by a command line argument. In this case the value fromsetConst(Object)
will be produced.- Parameters:
n
-"*"
,"+"
or"?"
- Returns:
- this
-
setConst
Sets constant values that are not read from the command line but are required for the various actions.
The const value defauls to
null
.- Parameters:
value
- The const value- Returns:
- this
-
setConst
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 toList
. The const value defauls tonull
. If you want to set non-List item, usesetConst(Object)
.- Parameters:
values
- The const values- Returns:
- this
-
setDefault
Sets value which should be used if the command line argument is not present.
The default value defaults to
null
.- Parameters:
value
- The default value- Returns:
- this
-
setDefault
Sets list of values which should be used if the command line argument is not present.
The default value defaults to
null
. The givenvalues
will be converted toList
. If you want to set non-List item, usesetDefault(Object)
.- Parameters:
values
- The default values- Returns:
- this
-
setDefault
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.- Parameters:
ctrl
- The special value to control default value handling.- Returns:
- this
-
type
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.
- Parameters:
type
- The type which the command line argument should be converted to.- Returns:
- this
-
type
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.
- Parameters:
type
- TheArgumentType
object- Returns:
- this
-
required
If
true
is given, this optional 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.- Parameters:
required
-true
orfalse
- Returns:
- this
-
action
Sets the action to be taken when this argument is encountered at the command line.- Parameters:
action
-ArgumentAction
object- Returns:
- this
-
choices
Sets
ArgumentChoice
object which inspects value so that it fulfills its criteria.This method is useful if more complex inspection is necessary than basic
choices(Object...)
.- Parameters:
choice
-ArgumentChoice
object.- Returns:
- this
-
choices
Sets a collection of the allowable values for the argument.- Parameters:
values
- A collection of the allowable values- Returns:
- this
-
choices
Sets a collection of the allowable values for the argument.- Parameters:
values
- A collection of the allowable values- Returns:
- this
-
dest
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 optional arguments,ArgumentParser
generates the default value ofdest
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_
.- Parameters:
dest
- The name of the attribute to be added- Returns:
- this
-
metavar
Set the name for the argument in usage messages.- Parameters:
metavar
- The name for the argument in usage messages- Returns:
- this
-
help
Sets the brief description of what the argument does.- Parameters:
help
- The brief description of what the argument does- Returns:
- this
-
help
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.- Parameters:
ctrl
- The special value to control help message handling.- Returns:
- this
-
textualName
String textualName()Returns textual representation of the argument name.
For optional arguments, this method returns the first argument given in
ArgumentParser.addArgument(String...)
. For positional arguments, this method returns the flags joined with "/", e.g.-f/--foo
.- Returns:
- The textual representation of the argument name.
-
getDest
String getDest()Returns dest value.- Returns:
- The dest value
-
getConst
Object getConst()Returns const value.- Returns:
- The const value
-
getDefault
Object getDefault()Returns default value.- Returns:
- The default value
-
getDefaultControl
FeatureControl getDefaultControl()Returns default control.- Returns:
- The default control
-
getHelpControl
FeatureControl getHelpControl()Returns help control.- Returns:
- The help control
-