- All Implemented Interfaces:
Argument
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ArgumentAction
private final ArgumentGroupImpl
private ArgumentChoice
private final ArgumentParserConfigurationImpl
private Object
private Object
private FeatureControl
private String
private String[]
private String
private FeatureControl
private int
private String[]
private int
private String
private boolean
private ArgumentType
<?> -
Constructor Summary
ConstructorsConstructorDescriptionArgumentImpl
(ArgumentParserConfigurationImpl config, String... nameOrFlags) ArgumentImpl
(ArgumentParserConfigurationImpl config, ArgumentGroupImpl argumentGroup, String... nameOrFlags) -
Method Summary
Modifier and TypeMethodDescriptionaction
(ArgumentAction action) Sets the action to be taken when this argument is encountered at the command line.final <E> ArgumentImpl
choices
(E... values) Sets a collection of the allowable values for the argument.<E> ArgumentImpl
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.convert
(ArgumentParserImpl parser, String value) private <T> ReflectArgumentType
<T> createReflectArgumentType
(Class<T> type) The name of the attribute to be added.private String
(package private) String
(package private) String
Short syntax is used in usage message, e.g.(package private) String
Short syntax is used in usage message, e.g.(package private) ArgumentGroupImpl
getConst()
Returns const value.Returns default value.Returns default control.getDest()
Returns dest value.(package private) String[]
getFlags()
getHelp()
Returns help control.(package private) int
String[]
(package private) int
getName()
(package private) String
Sets the brief description of what the argument does.help
(FeatureControl ctrl) Sets special value to control help message handling.(package private) boolean
boolean
private String
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.void
printHelp
(PrintWriter writer, boolean defaultHelp, TextWidthCounter textWidthCounter, int width) required
(boolean required) Iftrue
is given, this named argument must be specified in command line otherwise error will be issued.(package private) String[]
void
run
(ArgumentParserImpl parser, Map<String, Object> res, String flag, Object value, Consumer<Object> valueSetter) final <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.Sets constant values that are not read from the command line but are required for the various actions.final <E> ArgumentImpl
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> ArgumentImpl
Sets the type which the command line argument should be converted to.<T> ArgumentImpl
type
(ArgumentType<T> type) SetsArgumentType
object which converts command line argument to appropriate type.
-
Field Details
-
name_
-
flags_
-
dest_
-
type_
-
action_
-
choice_
-
const_
-
default_
-
defaultControl_
-
helpControl_
-
required_
private boolean required_ -
metavar_
-
minNumArg_
private int minNumArg_ -
maxNumArg_
private int maxNumArg_ -
help_
-
config_
-
argumentGroup_
-
-
Constructor Details
-
ArgumentImpl
ArgumentImpl(ArgumentParserConfigurationImpl config, String... nameOrFlags) -
ArgumentImpl
ArgumentImpl(ArgumentParserConfigurationImpl config, ArgumentGroupImpl argumentGroup, String... nameOrFlags)
-
-
Method Details
-
getPrimaryFlag
String getPrimaryFlag() -
textualName
Description copied from interface: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
.- Specified by:
textualName
in interfaceArgument
- Returns:
- The textual representation of the argument name.
-
formatShortSyntax
String formatShortSyntax()Short syntax is used in usage message, e.g. --foo BAR- Returns:
- short syntax
-
formatShortSyntaxNoBracket
String formatShortSyntaxNoBracket()Short syntax is used in usage message, e.g. --foo BAR, but without bracket when this is not required option.- Returns:
- short syntax
-
resolveMetavar
String[] resolveMetavar() -
formatMetavar
String formatMetavar() -
formatHelpTitle
-
printHelp
public void printHelp(PrintWriter writer, boolean defaultHelp, TextWidthCounter textWidthCounter, int width) -
convert
- Throws:
ArgumentParserException
-
nargs
Description copied from interface:Argument
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, useArgument.nargs(String)
. -
nargs
Description copied from interface: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 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 fromArgument.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 fromArgument.setConst(Object)
will be produced. -
setConst
Description copied from interface: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
. -
setConst
Description copied from interface: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 toList
. The const value defaults tonull
. If you want to set non-List item, useArgument.setConst(Object)
. -
setDefault
Description copied from interface:Argument
Sets value which should be used if the command line argument is not present.
The default value defaults to
null
.- Specified by:
setDefault
in interfaceArgument
- Parameters:
value
- The default value- Returns:
- this
-
setDefault
Description copied from interface:Argument
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, useArgument.setDefault(Object)
.- Specified by:
setDefault
in interfaceArgument
- Type Parameters:
E
- The type of the values- Parameters:
values
- The default values- Returns:
- this
-
setDefault
Description copied from interface: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.- Specified by:
setDefault
in interfaceArgument
- Parameters:
ctrl
- The special value to control default value handling.- Returns:
- this
-
createReflectArgumentType
-
type
Description copied from interface: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.
-
type
Description copied from interface: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.
- Specified by:
type
in interfaceArgument
- Type Parameters:
T
- The type of the value this argument accepts- Parameters:
type
- TheArgumentType
object- Returns:
- this
-
required
Description copied from interface: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. -
action
Description copied from interface:Argument
Sets the action to be taken when this argument is encountered at the command line.- Specified by:
action
in interfaceArgument
- Parameters:
action
-ArgumentAction
object- Returns:
- this
-
choices
Description copied from interface: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...)
.- Specified by:
choices
in interfaceArgument
- Parameters:
choice
-ArgumentChoice
object.- Returns:
- this
-
choices
Description copied from interface:Argument
Sets a collection of the allowable values for the argument. -
choices
Description copied from interface:Argument
Sets a collection of the allowable values for the argument. -
dest
Description copied from interface: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 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_
. -
metavar
Description copied from interface:Argument
Set the name for the argument in usage messages. -
help
Description copied from interface:Argument
Sets the brief description of what the argument does. -
help
Description copied from interface: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. -
isNamedArgument
boolean isNamedArgument() -
run
public void run(ArgumentParserImpl parser, Map<String, Object> res, String flag, Object value, Consumer<Object> valueSetter) throws ArgumentParserException- Throws:
ArgumentParserException
-
getDest
Description copied from interface:Argument
Returns dest value. -
getConst
Description copied from interface:Argument
Returns const value. -
getDefault
Description copied from interface:Argument
Returns default value.- Specified by:
getDefault
in interfaceArgument
- Returns:
- The default value
-
getDefaultControl
Description copied from interface:Argument
Returns default control.- Specified by:
getDefaultControl
in interfaceArgument
- Returns:
- The default control
-
getHelpControl
Description copied from interface:Argument
Returns help control.- Specified by:
getHelpControl
in interfaceArgument
- Returns:
- The help control
-
getName
-
isRequired
public boolean isRequired() -
getMinNumArg
int getMinNumArg() -
getMaxNumArg
int getMaxNumArg() -
getMetavar
-
getArgumentGroup
ArgumentGroupImpl getArgumentGroup() -
getAction
-
getHelp
-
getFlags
String[] getFlags() -
localize
-