Class CommandLine.Model.ArgSpec
- Direct Known Subclasses:
CommandLine.Model.OptionSpec
,CommandLine.Model.PositionalParamSpec
- Enclosing class:
- CommandLine.Model
CommandLine.Model.OptionSpec
and CommandLine.Model.PositionalParamSpec
.- Since:
- 3.0
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionarity()
Returns how many arguments this option or positional parameter requires.Class<?>[]
Returns auxiliary type information used when thetype()
is a genericCollection
,Map
or an abstract class.command()
Returns the command this option or positional parameter belongs to.Returns the explicitly set completion candidates for this option or positional parameter, valid enum constant names, ornull
if this option or positional parameter does not have any completion candidates and its type is not an enum.Returns one or moretype converters
to use to convert the command line argument into a strongly typed value (or key-value pair for map fields).Returns the default value to assign if this option or positional parameter was not specified on the command line, before splitting and type conversion.Returns the default value String for the purpose of displaying it in the description, without interpolating variables.defaultValueString
(boolean interpolateVariables) Returns the default value String displayed in the description; interpolating variables if specified.String[]
Returns the description of this option or positional parameter, after all variables have been rendered, including the${DEFAULT-VALUE}
and${COMPLETION-CANDIDATES}
variables.Returns the description key of this arg spec, used to get the description from a resource bundle.protected boolean
protected abstract Collection<String>
Subclasses should override to return a collection of additional description keys that may be used to find description text for this option or positional parameter in the resource bundle.getter()
Returns theCommandLine.Model.IGetter
that is responsible for supplying the value of this argument.<T> T
getValue()
Returns the current value of this argument.group()
Returns the groups this option or positional parameter belongs to, ornull
if this option is not part of a group.protected int
boolean
Determines whether the option or positional parameter will be reset to theinitialValue()
before parsing new input.boolean
hidden()
Returns whether this option should be excluded from the usage message.boolean
Returns whether usage syntax decorations around the paramLabel should be suppressed.Returns the initial value this option or positional parameter.boolean
Returns whether this option will prompt the user to enter a value on the command line.protected boolean
internalShowDefaultValue
(boolean usageHelpShowDefaults) Returns whether the default for this option or positional parameter should be shown, potentially overriding the specified global setting.boolean
abstract boolean
isOption()
Returnstrue
if this argument is a named option,false
otherwise.abstract boolean
Returnstrue
if this argument is a positional parameter,false
otherwise.messages()
Returns the Messages for this arg specification, ornull
.Sets the Messages for this ArgSpec, and returns this ArgSpec.Returns the original command line arguments matched by this option or positional parameter spec.Returns a customIParameterConsumer
to temporarily suspend picocli's parsing logic and process one or more command line arguments in a custom manner, ornull
.Returns the name of the option or positional parameter used in the usage help message.String[]
Deprecated.boolean
required()
Returns whether this is a required option or positional parameter without a default value.protected void
Sets theoriginalStringValues
to a new list instance.protected void
Sets thestringValues
to a new list instance.scope()
Returns theCommandLine.Model.IScope
that determines on which object to set the value (or from which object to get the value) of this argument.setter()
Returns theCommandLine.Model.ISetter
that is responsible for modifying the value of this argument.<T> T
setValue
(T newValue) Sets the value of this argument to the specified value and returns the previous value.<T> T
setValue
(T newValue, CommandLine commandLine) Deprecated.usesetValue(Object)
instead.Returns whether this option or positional parameter's default value should be shown in the usage help.Returns a regular expression to split option parameter values or""
if the value should not be split.Returns the untyped command line arguments matched by this option or positional parameter spec.toString()
Returns a string respresentation of this option or positional parameter.Class<?>
type()
Returns the type to convert the option or positional parameter to before setting the value.Returns the typed command line arguments matched by this option or positional parameter spec.typeInfo()
Returns theITypeInfo
that can be used both at compile time (by annotation processors) and at runtime.Returns the user object associated with this option or positional parameters.
-
Field Details
-
toString
-
-
Method Details
-
required
public boolean required()Returns whether this is a required option or positional parameter without a default value. If this argument is part of a group, this method returns whether this argument is required within the group (so it is not necessarily a required argument for the command).- See Also:
-
interactive
public boolean interactive()Returns whether this option will prompt the user to enter a value on the command line.- See Also:
-
description
Returns the description of this option or positional parameter, after all variables have been rendered, including the${DEFAULT-VALUE}
and${COMPLETION-CANDIDATES}
variables. UseCommandLine.Model.CommandSpec.interpolateVariables(Boolean)
to switch off variable expansion if needed.If a resource bundle has been set, this method will first try to find a value in the resource bundle: If the resource bundle has no entry for the
fully qualified commandName + "." + descriptionKey
or for the unqualifieddescriptionKey
, an attempt is made to find the option or positional parameter description using any of the additional description keys, first with thefully qualified commandName + "."
prefix, then without. -
getAdditionalDescriptionKeys
Subclasses should override to return a collection of additional description keys that may be used to find description text for this option or positional parameter in the resource bundle. -
descriptionKey
Returns the description key of this arg spec, used to get the description from a resource bundle.- Since:
- 3.6
- See Also:
-
renderedDescription
Deprecated.Usedescription()
instead -
arity
Returns how many arguments this option or positional parameter requires.- See Also:
-
paramLabel
Returns the name of the option or positional parameter used in the usage help message.- See Also:
-
hideParamSyntax
public boolean hideParamSyntax()Returns whether usage syntax decorations around the paramLabel should be suppressed. The default isfalse
: by default, the paramLabel is surrounded with'['
and']'
characters if the value is optional and followed by ellipses ("...") when multiple values can be specified.- Since:
- 3.6.0
-
auxiliaryTypes
Returns auxiliary type information used when thetype()
is a genericCollection
,Map
or an abstract class.- See Also:
-
converters
Returns one or moretype converters
to use to convert the command line argument into a strongly typed value (or key-value pair for map fields). This is useful when a particular option or positional parameter should use a custom conversion that is different from the normal conversion for the arg spec's type.- See Also:
-
splitRegex
Returns a regular expression to split option parameter values or""
if the value should not be split.- See Also:
-
type
Returns the type to convert the option or positional parameter to before setting the value. -
typeInfo
Returns theITypeInfo
that can be used both at compile time (by annotation processors) and at runtime.- Since:
- 4.0
-
userObject
Returns the user object associated with this option or positional parameters.- Returns:
- may return the annotated program element, or some other useful object
- Since:
- 4.0
-
defaultValue
Returns the default value to assign if this option or positional parameter was not specified on the command line, before splitting and type conversion. This method returns the programmatically set value; this may differ from the default value that is actually used: if this ArgSpec is part of a CommandSpec with aCommandLine.IDefaultValueProvider
, picocli will first try to obtain the default value from the default value provider, and this method is only called if the default provider isnull
or returned anull
value.- Returns:
- the programmatically set default value of this option/positional parameter,
returning
null
means this option or positional parameter does not have a default - See Also:
-
initialValue
Returns the initial value this option or positional parameter. IfhasInitialValue()
is true, the option will be reset to the initial value before parsing (regardless of whether a default value exists), to clear values that would otherwise remain from parsing previous input. -
hasInitialValue
public boolean hasInitialValue()Determines whether the option or positional parameter will be reset to theinitialValue()
before parsing new input. -
showDefaultValue
Returns whether this option or positional parameter's default value should be shown in the usage help. -
defaultValueString
Returns the default value String for the purpose of displaying it in the description, without interpolating variables.- See Also:
-
defaultValueString
Returns the default value String displayed in the description; interpolating variables if specified. If this ArgSpec is part of a CommandSpec with aCommandLine.IDefaultValueProvider
, this method will first try to obtain the default value from the default value provider; if the provider isnull
or if it returns anull
value, then next any value set todefaultValue()
is returned, and if this is alsonull
, finally the initial value is returned.- Parameters:
interpolateVariables
- whether to interpolate variables in thedefaultValue
attribute of this ArgSpec- Since:
- 4.0
- See Also:
-
completionCandidates
Returns the explicitly set completion candidates for this option or positional parameter, valid enum constant names, ornull
if this option or positional parameter does not have any completion candidates and its type is not an enum.- Returns:
- the completion candidates for this option or positional parameter, valid enum constant names,
or
null
- Since:
- 3.2
-
parameterConsumer
Returns a customIParameterConsumer
to temporarily suspend picocli's parsing logic and process one or more command line arguments in a custom manner, ornull
. An example of when this may be useful is when passing arguments through to another program.- Since:
- 4.0
-
getter
Returns theCommandLine.Model.IGetter
that is responsible for supplying the value of this argument. -
setter
Returns theCommandLine.Model.ISetter
that is responsible for modifying the value of this argument. -
scope
Returns theCommandLine.Model.IScope
that determines on which object to set the value (or from which object to get the value) of this argument. -
getValue
Returns the current value of this argument. Delegates to the currentgetter()
.- Throws:
CommandLine.PicocliException
-
setValue
Sets the value of this argument to the specified value and returns the previous value. Delegates to the currentsetter()
.- Throws:
CommandLine.PicocliException
-
setValue
@Deprecated public <T> T setValue(T newValue, CommandLine commandLine) throws CommandLine.PicocliException Deprecated.usesetValue(Object)
instead. This was a design mistake.Sets the value of this argument to the specified value and returns the previous value. Delegates to the currentsetter()
.- Throws:
CommandLine.PicocliException
- Since:
- 3.5
-
isMultiValue
public boolean isMultiValue() -
isOption
public abstract boolean isOption()Returnstrue
if this argument is a named option,false
otherwise. -
isPositional
public abstract boolean isPositional()Returnstrue
if this argument is a positional parameter,false
otherwise. -
group
Returns the groups this option or positional parameter belongs to, ornull
if this option is not part of a group.- Since:
- 4.0
-
command
Returns the command this option or positional parameter belongs to.Beware that it is possible to programmatically add an option or positional parameter to more than one command model. (This will not happen in models that are auto-generated from annotations). In that case this method will only return the one it was added to last.
If the option or positional parameter has not yet been attached to a command,
null
will be returned.- Since:
- 4.1
-
stringValues
Returns the untyped command line arguments matched by this option or positional parameter spec.- Returns:
- the matched arguments after splitting, but before type conversion.
For map properties,
"key=value"
values are split into the key and the value part.
-
typedValues
Returns the typed command line arguments matched by this option or positional parameter spec.- Returns:
- the matched arguments after splitting and type conversion.
For map properties,
"key=value"
values are split into the key and the value part.
-
resetStringValues
protected void resetStringValues()Sets thestringValues
to a new list instance. -
originalStringValues
Returns the original command line arguments matched by this option or positional parameter spec.- Returns:
- the matched arguments as found on the command line: empty Strings for options without value, the
values have not been split, and for map properties values may look like
"key=value"
-
resetOriginalStringValues
protected void resetOriginalStringValues()Sets theoriginalStringValues
to a new list instance. -
internalShowDefaultValue
protected boolean internalShowDefaultValue(boolean usageHelpShowDefaults) Returns whether the default for this option or positional parameter should be shown, potentially overriding the specified global setting.- Parameters:
usageHelpShowDefaults
- whether the command's UsageMessageSpec is configured to show default values.
-
messages
Returns the Messages for this arg specification, ornull
.- Since:
- 3.6
-
messages
Sets the Messages for this ArgSpec, and returns this ArgSpec.- Parameters:
msgs
- the new Messages value, may benull
- Since:
- 3.6
- See Also:
-
toString
Returns a string respresentation of this option or positional parameter. -
equalsImpl
-
hashCodeImpl
protected int hashCodeImpl()
-
description()
instead