Class ArgumentImpl
- java.lang.Object
-
- net.sourceforge.argparse4j.internal.ArgumentImpl
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArgumentImplaction(ArgumentAction action)Sets the action to be taken when this argument is encountered at the command line.<E> ArgumentImplchoices(E... values)Sets a collection of the allowable values for the argument.<E> ArgumentImplchoices(Collection<E> values)Sets a collection of the allowable values for the argument.ArgumentImplchoices(ArgumentChoice choice)SetsArgumentChoiceobject which inspects value so that it fulfills its criteria.Objectconvert(ArgumentParserImpl parser, String value)ArgumentImpldest(String dest)The name of the attribute to be added.ArgumentActiongetAction()ObjectgetConst()Returns const value.ObjectgetDefault()Returns default value.FeatureControlgetDefaultControl()Returns default control.StringgetDest()Returns dest value.StringgetHelp()FeatureControlgetHelpControl()Returns help control.String[]getMetavar()StringgetName()ArgumentImplhelp(String help)Sets the brief description of what the argument does.ArgumentImplhelp(FeatureControl ctrl)Sets special value to control help message handling.booleanisRequired()ArgumentImplmetavar(String... metavar)Set the name for the argument in usage messages.ArgumentImplnargs(int n)Sets the number of command line arguments that should be consumed.ArgumentImplnargs(String n)Sets the number of command line arguments that should be consumed.voidprintHelp(PrintWriter writer, boolean defaultHelp, TextWidthCounter textWidthCounter, int width)ArgumentImplrequired(boolean required)Iftrueis given, this named argument must be specified in command line otherwise error will be issued.voidrun(ArgumentParserImpl parser, Map<String,Object> res, String flag, Object value, Consumer<Object> valueSetter)<E> ArgumentImplsetConst(E... values)Sets list of constant values that are not read from the command line but are required for the various actions.ArgumentImplsetConst(Object value)Sets constant values that are not read from the command line but are required for the various actions.<E> ArgumentImplsetDefault(E... values)Sets list of values which should be used if the command line argument is not present.ArgumentImplsetDefault(Object value)Sets value which should be used if the command line argument is not present.ArgumentImplsetDefault(FeatureControl ctrl)Sets special value to control default value handling.StringtextualName()Returns textual representation of the argument name.<T> ArgumentImpltype(Class<T> type)Sets the type which the command line argument should be converted to.<T> ArgumentImpltype(ArgumentType<T> type)SetsArgumentTypeobject which converts command line argument to appropriate type.
-
-
-
Method Detail
-
textualName
public String textualName()
Description copied from interface:ArgumentReturns 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:
textualNamein interfaceArgument- Returns:
- The textual representation of the argument name.
-
printHelp
public void printHelp(PrintWriter writer, boolean defaultHelp, TextWidthCounter textWidthCounter, int width)
-
convert
public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException
- Throws:
ArgumentParserException
-
nargs
public ArgumentImpl nargs(int n)
Description copied from interface:ArgumentSets the number of command line arguments that should be consumed.
Don't give this method
'*','+'or'?'. They are converted tointvalue and it is not what you expect. For these strings, useArgument.nargs(String).
-
nargs
public ArgumentImpl nargs(String n)
Description copied from interface:ArgumentSets 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
public ArgumentImpl setConst(Object value)
Description copied from interface:ArgumentSets constant values that are not read from the command line but are required for the various actions.
The const value defaults to
null.
-
setConst
@SafeVarargs public final <E> ArgumentImpl setConst(E... values)
Description copied from interface:ArgumentSets list of constant values that are not read from the command line but are required for the various actions.
The given
valueswill be converted toList. The const value defaults tonull. If you want to set non-List item, useArgument.setConst(Object).
-
setDefault
public ArgumentImpl setDefault(Object value)
Description copied from interface:ArgumentSets value which should be used if the command line argument is not present.
The default value defaults to
null.- Specified by:
setDefaultin interfaceArgument- Parameters:
value- The default value- Returns:
- this
-
setDefault
@SafeVarargs public final <E> ArgumentImpl setDefault(E... values)
Description copied from interface:ArgumentSets list of values which should be used if the command line argument is not present.
The default value defaults to
null. The givenvalueswill be converted toList. If you want to set non-List item, useArgument.setDefault(Object).- Specified by:
setDefaultin interfaceArgument- Type Parameters:
E- The type of the values- Parameters:
values- The default values- Returns:
- this
-
setDefault
public ArgumentImpl setDefault(FeatureControl ctrl)
Description copied from interface:ArgumentSets special value to control default value handling.
Currently, only
FeatureControl.SUPPRESSis available. If it is given, default value is not add as a attribute.- Specified by:
setDefaultin interfaceArgument- Parameters:
ctrl- The special value to control default value handling.- Returns:
- this
-
type
public <T> ArgumentImpl type(Class<T> type)
Description copied from interface:ArgumentSets 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
public <T> ArgumentImpl type(ArgumentType<T> type)
Description copied from interface:ArgumentSets
ArgumentTypeobject 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:
typein interfaceArgument- Type Parameters:
T- The type of the value this argument accepts- Parameters:
type- TheArgumentTypeobject- Returns:
- this
-
required
public ArgumentImpl required(boolean required)
Description copied from interface:ArgumentIf
trueis 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
public ArgumentImpl action(ArgumentAction action)
Description copied from interface:ArgumentSets the action to be taken when this argument is encountered at the command line.- Specified by:
actionin interfaceArgument- Parameters:
action-ArgumentActionobject- Returns:
- this
-
choices
public ArgumentImpl choices(ArgumentChoice choice)
Description copied from interface:ArgumentSets
ArgumentChoiceobject 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:
choicesin interfaceArgument- Parameters:
choice-ArgumentChoiceobject.- Returns:
- this
-
choices
public <E> ArgumentImpl choices(Collection<E> values)
Description copied from interface:ArgumentSets a collection of the allowable values for the argument.
-
choices
@SafeVarargs public final <E> ArgumentImpl choices(E... values)
Description copied from interface:ArgumentSets a collection of the allowable values for the argument.
-
dest
public ArgumentImpl dest(String dest)
Description copied from interface:ArgumentThe 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,ArgumentParsergenerates the default value ofdestby taking the first long option string and stripping away the initial--string. If no long option strings were supplied,destwill be derived from the first short option string by stripping the initial-character. Any internal-characters will be converted to_.
-
metavar
public ArgumentImpl metavar(String... metavar)
Description copied from interface:ArgumentSet the name for the argument in usage messages.
-
help
public ArgumentImpl help(String help)
Description copied from interface:ArgumentSets the brief description of what the argument does.
-
help
public ArgumentImpl help(FeatureControl ctrl)
Description copied from interface:ArgumentSets special value to control help message handling.
Currently, only
FeatureControl.SUPPRESSis available. If it is given, the help entry for this option is not displayed in the help message.
-
run
public void run(ArgumentParserImpl parser, Map<String,Object> res, String flag, Object value, Consumer<Object> valueSetter) throws ArgumentParserException
- Throws:
ArgumentParserException
-
getDefault
public Object getDefault()
Description copied from interface:ArgumentReturns default value.- Specified by:
getDefaultin interfaceArgument- Returns:
- The default value
-
getDefaultControl
public FeatureControl getDefaultControl()
Description copied from interface:ArgumentReturns default control.- Specified by:
getDefaultControlin interfaceArgument- Returns:
- The default control
-
getHelpControl
public FeatureControl getHelpControl()
Description copied from interface:ArgumentReturns help control.- Specified by:
getHelpControlin interfaceArgument- Returns:
- The help control
-
getName
public String getName()
-
isRequired
public boolean isRequired()
-
getMetavar
public String[] getMetavar()
-
getAction
public ArgumentAction getAction()
-
getHelp
public String getHelp()
-
-