Package picocli
Class CommandLine.Model.ArgSpec
- java.lang.Object
-
- picocli.CommandLine.Model.ArgSpec
-
- Direct Known Subclasses:
CommandLine.Model.OptionSpec,CommandLine.Model.PositionalParamSpec
- Enclosing class:
- CommandLine.Model
public abstract static class CommandLine.Model.ArgSpec extends Object
Models the shared attributes ofCommandLine.Model.OptionSpecandCommandLine.Model.PositionalParamSpec.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CommandLine.Rangearity()Returns how many arguments this option or positional parameter requires.Class<?>[]auxiliaryTypes()Returns auxiliary type information used when thetype()is a genericCollection,Mapor an abstract class.Iterable<String>completionCandidates()Returns the explicitly set completion candidates for this option or positional parameter, valid enum constant names, ornullif this option or positional parameter does not have any completion candidates and its type is not an enum.CommandLine.ITypeConverter<?>[]converters()Returns one or moretype convertersto use to convert the command line argument into a strongly typed value (or key-value pair for map fields).StringdefaultValue()Returns the default value of this option or positional parameter, before splitting and type conversion.StringdefaultValueString()Returns the default value String displayed in the description.String[]description()Returns the description template of this option, before variables are rendered.StringdescriptionKey()Returns the description key of this arg spec, used to get the description from a resource bundle.protected booleanequalsImpl(CommandLine.Model.ArgSpec other)CommandLine.Model.IGettergetter()Returns theCommandLine.Model.IGetterthat is responsible for supplying the value of this argument.<T> TgetValue()Returns the current value of this argument.protected inthashCodeImpl()booleanhasInitialValue()Determines whether the option or positional parameter will be reset to theinitialValue()before parsing new input.booleanhidden()Returns whether this option should be excluded from the usage message.booleanhideParamSyntax()Returns whether usage syntax decorations around the paramLabel should be suppressed.ObjectinitialValue()Returns the initial value this option or positional parameter.booleaninteractive()Returns whether this option will prompt the user to enter a value on the command line.protected booleaninternalShowDefaultValue(boolean usageHelpShowDefaults)Returns whether the default for this option or positional parameter should be shown, potentially overriding the specified global setting.booleanisMultiValue()abstract booleanisOption()Returnstrueif this argument is a named option,falseotherwise.abstract booleanisPositional()Returnstrueif this argument is a positional parameter,falseotherwise.CommandLine.Model.Messagesmessages()Returns the Messages for this arg specification, ornull.CommandLine.Model.ArgSpecmessages(CommandLine.Model.Messages msgs)Sets the Messages for this ArgSpec, and returns this ArgSpec.List<String>originalStringValues()Returns the original command line arguments matched by this option or positional parameter spec.StringparamLabel()Returns the name of the option or positional parameter used in the usage help message.String[]renderedDescription()Returns the description of this option, after variables are rendered.booleanrequired()Returns whether this is a required option or positional parameter.protected voidresetOriginalStringValues()Sets theoriginalStringValuesto a new list instance.protected voidresetStringValues()Sets thestringValuesto a new list instance.CommandLine.Model.ISettersetter()Returns theCommandLine.Model.ISetterthat is responsible for modifying the value of this argument.<T> TsetValue(T newValue)Sets the value of this argument to the specified value and returns the previous value.<T> TsetValue(T newValue, CommandLine commandLine)Deprecated.usesetValue(Object)instead.CommandLine.Help.VisibilityshowDefaultValue()Returns whether this option or positional parameter's default value should be shown in the usage help.StringsplitRegex()Returns a regular expression to split option parameter values or""if the value should not be split.List<String>stringValues()Returns the untyped command line arguments matched by this option or positional parameter spec.StringtoString()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.
-
-
-
Field Detail
-
toString
protected String toString
-
-
Method Detail
-
required
public boolean required()
Returns whether this is a required option or positional parameter.- See Also:
CommandLine.Option.required()
-
interactive
public boolean interactive()
Returns whether this option will prompt the user to enter a value on the command line.- See Also:
CommandLine.Option.interactive()
-
description
public String[] description()
Returns the description template of this option, before variables are rendered.- See Also:
CommandLine.Option.description()
-
descriptionKey
public String descriptionKey()
Returns the description key of this arg spec, used to get the description from a resource bundle.- Since:
- 3.6
- See Also:
CommandLine.Option.descriptionKey(),CommandLine.Parameters.descriptionKey()
-
renderedDescription
public String[] renderedDescription()
Returns the description of this option, after variables are rendered. Used when generating the usage documentation.- Since:
- 3.2
- See Also:
CommandLine.Option.description()
-
arity
public CommandLine.Range arity()
Returns how many arguments this option or positional parameter requires.- See Also:
CommandLine.Option.arity()
-
paramLabel
public String paramLabel()
Returns the name of the option or positional parameter used in the usage help message.- See Also:
CommandLine.Option.paramLabel()
-
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
public Class<?>[] auxiliaryTypes()
Returns auxiliary type information used when thetype()is a genericCollection,Mapor an abstract class.- See Also:
CommandLine.Option.type()
-
converters
public CommandLine.ITypeConverter<?>[] converters()
Returns one or moretype convertersto 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:
CommandLine.Option.converter()
-
splitRegex
public String splitRegex()
Returns a regular expression to split option parameter values or""if the value should not be split.- See Also:
CommandLine.Option.split()
-
hidden
public boolean hidden()
Returns whether this option should be excluded from the usage message.- See Also:
CommandLine.Option.hidden()
-
type
public Class<?> type()
Returns the type to convert the option or positional parameter to before setting the value.
-
defaultValue
public String defaultValue()
Returns the default value of this option or positional parameter, 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 isnullor returned anullvalue.- Returns:
- the programmatically set default value of this option/positional parameter,
returning
nullmeans this option or positional parameter does not have a default - See Also:
CommandLine.Model.CommandSpec.defaultValueProvider()
-
initialValue
public Object 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
public CommandLine.Help.Visibility showDefaultValue()
Returns whether this option or positional parameter's default value should be shown in the usage help.
-
defaultValueString
public String defaultValueString()
Returns the default value String displayed in the description. 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 isnullor if it returns anullvalue, then next any value set todefaultValue()is returned, and if this is alsonull, finally the initial value is returned.
-
completionCandidates
public Iterable<String> completionCandidates()
Returns the explicitly set completion candidates for this option or positional parameter, valid enum constant names, ornullif 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
-
getter
public CommandLine.Model.IGetter getter()
Returns theCommandLine.Model.IGetterthat is responsible for supplying the value of this argument.
-
setter
public CommandLine.Model.ISetter setter()
Returns theCommandLine.Model.ISetterthat is responsible for modifying the value of this argument.
-
getValue
public <T> T getValue() throws CommandLine.PicocliExceptionReturns the current value of this argument. Delegates to the currentgetter().- Throws:
CommandLine.PicocliException
-
setValue
public <T> T setValue(T newValue) throws CommandLine.PicocliExceptionSets 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()
Returnstrueif this argument is a named option,falseotherwise.
-
isPositional
public abstract boolean isPositional()
Returnstrueif this argument is a positional parameter,falseotherwise.
-
stringValues
public List<String> 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
public List<Object> 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 thestringValuesto a new list instance.
-
originalStringValues
public List<String> 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 theoriginalStringValuesto 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
public CommandLine.Model.Messages messages()
Returns the Messages for this arg specification, ornull.- Since:
- 3.6
-
messages
public CommandLine.Model.ArgSpec messages(CommandLine.Model.Messages msgs)
Sets the Messages for this ArgSpec, and returns this ArgSpec.- Parameters:
msgs- the new Messages value, may benull- Since:
- 3.6
- See Also:
CommandLine.Command.resourceBundle(),CommandLine.Model.OptionSpec.description(),CommandLine.Model.PositionalParamSpec.description()
-
toString
public String toString()
Returns a string respresentation of this option or positional parameter.
-
equalsImpl
protected boolean equalsImpl(CommandLine.Model.ArgSpec other)
-
hashCodeImpl
protected int hashCodeImpl()
-
-