public abstract static class CommandLine.Model.ArgSpec extends Object
CommandLine.Model.OptionSpec
and CommandLine.Model.PositionalParamSpec
.Modifier and Type | Field and Description |
---|---|
protected CommandLine.Model.IAnnotatedElement |
annotatedElement |
protected String |
toString |
protected CommandLine.Model.ITypeInfo |
typeInfo |
protected boolean |
valueIsDefaultValue |
Modifier and Type | Method and Description |
---|---|
CommandLine.Range |
arity()
Returns how many arguments this option or positional parameter requires.
|
Class<?>[] |
auxiliaryTypes()
|
CommandLine.Model.CommandSpec |
command()
Returns the command this option or positional parameter belongs to.
|
Iterable<String> |
completionCandidates()
Returns the explicitly set completion candidates for this option or positional parameter, valid enum
constant names, or
null if this option or positional parameter does not have any completion
candidates and its type is not an enum. |
CommandLine.ITypeConverter<?>[] |
converters()
Returns one or more
type converters to use to convert the command line
argument into a strongly typed value (or key-value pair for map fields). |
String |
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.
|
String |
defaultValueString()
Returns the default value String for the purpose of displaying it in the description, without interpolating variables.
|
String |
defaultValueString(boolean interpolateVariables)
Returns the default value String displayed in the description; interpolating variables if specified.
|
String[] |
description()
Returns the description of this option or positional parameter, after all variables have been rendered,
including the
${DEFAULT-VALUE} and ${COMPLETION-CANDIDATES} variables. |
String |
descriptionKey()
Returns the description key of this arg spec, used to get the description from a resource bundle.
|
boolean |
echo()
Returns whether the user input is echoed to the console or not for an interactive option or positional parameter when asking for user input.
|
protected boolean |
equalsImpl(CommandLine.Model.ArgSpec other) |
protected abstract Collection<String> |
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.
|
CommandLine.Model.IGetter |
getter()
Returns the
CommandLine.Model.IGetter that is responsible for supplying the value of this argument. |
<T> T |
getValue()
Returns the current value of this argument.
|
CommandLine.Model.ArgGroupSpec |
group()
Returns the groups this option or positional parameter belongs to, or
null if this option is not part of a group. |
protected int |
hashCodeImpl() |
boolean |
hasInitialValue()
Determines whether the option or positional parameter will be reset to the
initialValue()
before parsing new input. |
boolean |
hidden()
Returns whether this option should be excluded from the usage message.
|
boolean |
hideParamSyntax()
Returns whether usage syntax decorations around the paramLabel should be suppressed.
|
boolean |
inherited()
Returns whether this option is inherited from a parent command.
|
Object |
initialValue()
Returns the initial value of this option or positional parameter: the value that, if
hasInitialValue() is true,
the option will be reset to before parsing (regardless of whether a default value exists),
to clear values that would otherwise remain from parsing previous input. |
boolean |
interactive()
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 |
isMultiValue()
|
abstract boolean |
isOption()
Returns
true if this argument is a named option, false otherwise. |
abstract boolean |
isPositional()
Returns
true if this argument is a positional parameter, false otherwise. |
boolean |
isValueGettable()
Check whether the
getValue() method is able to get an actual value from the current getter() . |
String |
mapFallbackValue()
Returns the fallback value for this Map option or positional parameter: the value that is put into the Map when only the
key is specified for the option or positional parameter, like
-Dkey instead of -Dkey=value . |
CommandLine.Model.Messages |
messages()
Returns the Messages for this arg specification, or
null . |
CommandLine.Model.ArgSpec |
messages(CommandLine.Model.Messages msgs)
Sets the Messages for this ArgSpec, and returns this ArgSpec.
|
boolean |
originallyRequired()
Returns the original value of the option's required attribute, regardless of whether the option is used in an exclusive group or not.
|
List<String> |
originalStringValues()
Returns the original command line arguments matched by this option or positional parameter spec.
|
CommandLine.IParameterConsumer |
parameterConsumer()
Returns a custom
IParameterConsumer to temporarily suspend picocli's parsing logic
and process one or more command line arguments in a custom manner, or null . |
String |
paramLabel()
Returns the name of the option or positional parameter used in the usage help message.
|
CommandLine.IParameterPreprocessor |
preprocessor()
Returns a custom
IParameterPreprocessor to either replace or complement picocli's parsing logic
for the parameter(s) of this option or position. |
String |
prompt()
Returns the text displayed to the end user for an interactive option or positional parameter when asking for user input.
|
String[] |
renderedDescription()
Deprecated.
Use
description() instead |
boolean |
required()
Returns whether this is a required option or positional parameter without a default value.
|
protected void |
resetOriginalStringValues()
Sets the
originalStringValues to a new list instance. |
protected void |
resetStringValues()
Sets the
stringValues to a new list instance. |
CommandLine.Model.ArgSpec |
root()
Returns the root option or positional parameter (on the parent command), if this option or positional parameter was inherited;
or
null if it was not. |
CommandLine.Model.IScope |
scope()
Returns the binding
CommandLine.Model.IScope that determines on which object to set the value (or from which object to get the value) of this argument. |
CommandLine.ScopeType |
scopeType()
Returns the scope of this argument; is it local, or inherited (it applies to this command as well as all sub- and sub-subcommands).
|
CommandLine.Model.ISetter |
setter()
Returns the
CommandLine.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.
use
setValue(Object) instead. This was a design mistake. |
CommandLine.Help.Visibility |
showDefaultValue()
Returns whether this option or positional parameter's default value should be shown in the usage help.
|
String |
splitRegex()
Returns a regular expression to split option parameter values or
"" if the value should not be split. |
String |
splitRegexSynopsisLabel()
Returns a regular expression to split option parameter for usage information.
|
List<String> |
stringValues()
Returns the untyped command line arguments matched by this option or positional parameter spec.
|
String |
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.
|
List<Object> |
typedValues()
Returns the typed command line arguments matched by this option or positional parameter spec.
|
CommandLine.Model.ITypeInfo |
typeInfo()
Returns the
ITypeInfo that can be used both at compile time (by annotation processors) and at runtime. |
Object |
userObject()
Returns the user object associated with this option or positional parameters.
|
protected final CommandLine.Model.ITypeInfo typeInfo
protected boolean valueIsDefaultValue
protected final CommandLine.Model.IAnnotatedElement annotatedElement
protected String toString
public boolean originallyRequired()
CommandLine.Option.required()
public boolean required()
CommandLine.Option.required()
public boolean interactive()
public boolean echo()
CommandLine.Option.echo()
,
CommandLine.Parameters.echo()
public String prompt()
CommandLine.Option.prompt()
,
CommandLine.Parameters.prompt()
public String[] description()
${DEFAULT-VALUE}
and ${COMPLETION-CANDIDATES}
variables.
Use CommandLine.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 unqualified descriptionKey
,
an attempt is made to find the option or positional parameter description using any of the
additional description keys, first with the fully qualified commandName + "."
prefix, then without.
protected abstract Collection<String> getAdditionalDescriptionKeys()
public String descriptionKey()
CommandLine.Option.descriptionKey()
,
CommandLine.Parameters.descriptionKey()
@Deprecated public String[] renderedDescription()
description()
insteadpublic CommandLine.Range arity()
CommandLine.Option.arity()
public String paramLabel()
public boolean hideParamSyntax()
false
: by default, the paramLabel is surrounded with '['
and ']'
characters
if the value is optional and followed by ellipses ("...") when multiple values can be specified.public Class<?>[] auxiliaryTypes()
type()
is a generic type like
Collection
, Map
or Optional
; returns the concrete type when type()
is an abstract class, otherwise, returns the same as type()
.CommandLine.Option.type()
public CommandLine.ITypeConverter<?>[] converters()
type 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.CommandLine.Option.converter()
public String splitRegex()
""
if the value should not be split.CommandLine.Option.split()
public String splitRegexSynopsisLabel()
CommandLine.Option.splitSynopsisLabel()
public boolean hidden()
CommandLine.Option.hidden()
public boolean inherited()
CommandLine.Option.scope()
public CommandLine.Model.ArgSpec root()
null
if it was not.CommandLine.Option.scope()
public Class<?> type()
List
, Map
, or Optional
,
in which case the type or types of the elements are returned by auxiliaryTypes()
.public CommandLine.Model.ITypeInfo typeInfo()
ITypeInfo
that can be used both at compile time (by annotation processors) and at runtime.public Object userObject()
public String mapFallbackValue()
-Dkey
instead of -Dkey=value
.
If no mapFallbackValue
is set, key-only Map parameters like -Dkey
are considered invalid user input and cause a CommandLine.ParameterException
to be thrown.
By default, this method returns a special "__unspecified__" value indicating that no mapFallbackValue
was set.
CommandLine.Option.mapFallbackValue()
,
CommandLine.Parameters.mapFallbackValue()
public String defaultValue()
CommandLine.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 is
null
or returned a null
value.null
means this option or positional parameter does not have a defaultCommandLine.Model.CommandSpec.defaultValueProvider()
,
CommandLine.Model.OptionSpec.fallbackValue()
public Object initialValue()
hasInitialValue()
is true,
the option will be reset to before parsing (regardless of whether a default value exists),
to clear values that would otherwise remain from parsing previous input.public boolean hasInitialValue()
initialValue()
before parsing new input.public CommandLine.Help.Visibility showDefaultValue()
public String defaultValueString()
defaultValueString(boolean)
public String defaultValueString(boolean interpolateVariables)
CommandLine.IDefaultValueProvider
, this method will first try to obtain
the default value from the default value provider; if the provider is null
or if it
returns a null
value, then next any value set to defaultValue()
is returned, and if this is also null
, finally the initial value is returned.interpolateVariables
- whether to interpolate variables in the defaultValue
attribute of this ArgSpecCommandLine.Model.CommandSpec.defaultValueProvider()
,
defaultValue()
public Iterable<String> completionCandidates()
null
if this option or positional parameter does not have any completion
candidates and its type is not an enum.null
public CommandLine.IParameterConsumer parameterConsumer()
IParameterConsumer
to temporarily suspend picocli's parsing logic
and process one or more command line arguments in a custom manner, or null
.
An example of when this may be useful is when passing arguments through to another program.public CommandLine.IParameterPreprocessor preprocessor()
IParameterPreprocessor
to either replace or complement picocli's parsing logic
for the parameter(s) of this option or position.public CommandLine.Model.IGetter getter()
CommandLine.Model.IGetter
that is responsible for supplying the value of this argument.public CommandLine.Model.ISetter setter()
CommandLine.Model.ISetter
that is responsible for modifying the value of this argument.public CommandLine.Model.IScope scope()
CommandLine.Model.IScope
that determines on which object to set the value (or from which object to get the value) of this argument.public CommandLine.ScopeType scopeType()
public boolean isValueGettable()
getValue()
method is able to get an actual value from the current getter()
.public <T> T getValue() throws CommandLine.PicocliException
getter()
.CommandLine.PicocliException
public <T> T setValue(T newValue) throws CommandLine.PicocliException
setter()
.CommandLine.PicocliException
@Deprecated public <T> T setValue(T newValue, CommandLine commandLine) throws CommandLine.PicocliException
setValue(Object)
instead. This was a design mistake.setter()
.CommandLine.PicocliException
public boolean isMultiValue()
public abstract boolean isOption()
true
if this argument is a named option, false
otherwise.public abstract boolean isPositional()
true
if this argument is a positional parameter, false
otherwise.public CommandLine.Model.ArgGroupSpec group()
null
if this option is not part of a group.public CommandLine.Model.CommandSpec command()
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.
public List<String> stringValues()
"key=value"
values are split into the key and the value part.public List<Object> typedValues()
"key=value"
values are split into the key and the value part.protected void resetStringValues()
stringValues
to a new list instance.public List<String> originalStringValues()
"key=value"
protected void resetOriginalStringValues()
originalStringValues
to a new list instance.protected boolean internalShowDefaultValue(boolean usageHelpShowDefaults)
usageHelpShowDefaults
- whether the command's UsageMessageSpec is configured to show default values.public CommandLine.Model.Messages messages()
null
.public CommandLine.Model.ArgSpec messages(CommandLine.Model.Messages msgs)
msgs
- the new Messages value, may be null
CommandLine.Command.resourceBundle()
,
description()
,
description()
public String toString()
protected boolean equalsImpl(CommandLine.Model.ArgSpec other)
protected int hashCodeImpl()