Class CommandLine.Model.PositionalParamSpec
- java.lang.Object
-
- picocli.CommandLine.Model.ArgSpec
-
- picocli.CommandLine.Model.PositionalParamSpec
-
- Enclosing class:
- CommandLine.Model
public static class CommandLine.Model.PositionalParamSpec extends CommandLine.Model.ArgSpec
ThePositionalParamSpecclass models aspects of a positional parameter of a command, including whether it is required or optional, and attributes for the usage help message describing the positional parameter.Positional parameters have an
index(or a range of indices). A positional parameter is matched when the parser encounters a command line argument at that index. Named options and their parameters do not change the index counter, so the command line can contain a mixture of positional parameters and named options.Depending on the positional parameter's
arity, the parser may consume multiple command line arguments starting from the current index. The parser will callsetValueon thePositionalParamSpecfor each of the parameters encountered. For multi-value positional parameters, thetypemay be an array, aCollectionor aMap. In this case the parser will get the data structure by callinggetValueand modify the contents of this data structure. (In the case of arrays, the array is replaced with a new instance with additional elements.)Before calling the setter, picocli converts the positional parameter value from a String to the parameter's type.
- If a positional parameter-specific
converteris configured, this will be used for type conversion. If the positional parameter's type is aMap, the map may have different types for its keys and its values, soconvertersshould provide two converters: one for the map keys and one for the map values. - Otherwise, the positional parameter's
typeis used to look up a converter in the list of registered converters. For multi-value positional parameters, thetypemay be an array, or aCollectionor aMap. In that case the elements are converted based on the positional parameter'sauxiliaryTypes. The auxiliaryType is used to look up the converter(s) to use to convert the individual parameter values. Maps may have different types for its keys and its values, soauxiliaryTypesshould provide two types: one for the map keys and one for the map values.
PositionalParamSpecobjects are used by the picocli command line interpreter and help message generator. Picocli can construct aPositionalParamSpecautomatically from fields and methods with@Parametersannotations. Alternatively aPositionalParamSpeccan be constructed programmatically.When a
PositionalParamSpecis created from a@Parameters-annotated field or method, it is "bound" to that field or method: this field is set (or the method is invoked) when the position is matched andsetValueis called. Programmatically constructedPositionalParamSpecinstances will remember the value passed to thesetValuemethod so it can be retrieved with thegetValuemethod. This behaviour can be customized by installing a customCommandLine.Model.IGetterandCommandLine.Model.ISetteron thePositionalParamSpec.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandLine.Model.PositionalParamSpec.BuilderBuilder responsible for creating validPositionalParamSpecobjects.
-
Field Summary
-
Fields inherited from class picocli.CommandLine.Model.ArgSpec
annotatedElement, toString, typeInfo, valueIsDefaultValue
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CommandLine.Model.PositionalParamSpec.Builderbuilder()static CommandLine.Model.PositionalParamSpec.Builderbuilder(CommandLine.Model.IAnnotatedElement source, CommandLine.IFactory factory)static CommandLine.Model.PositionalParamSpec.Builderbuilder(CommandLine.Model.PositionalParamSpec original)Returns a Builder initialized from the specifiedPositionalSpec.booleanequals(java.lang.Object obj)protected java.util.Collection<java.lang.String>getAdditionalDescriptionKeys()Returns the additional lookup keys for finding description lines in the resource bundle for this positional parameter.inthashCode()CommandLine.Rangeindex()Returns an index or range specifying which of the command line arguments should be assigned to this positional parameter.booleanisOption()Returnstrueif this argument is a named option,falseotherwise.booleanisPositional()Returnstrueif this argument is a positional parameter,falseotherwise.CommandLine.Model.PositionalParamSpec.BuildertoBuilder()Returns a new Builder initialized with the attributes from thisPositionalParamSpec.-
Methods inherited from class picocli.CommandLine.Model.ArgSpec
arity, auxiliaryTypes, command, completionCandidates, converters, defaultValue, defaultValueString, defaultValueString, description, descriptionKey, echo, equalsImpl, getter, getValue, group, hashCodeImpl, hasInitialValue, hidden, hideParamSyntax, inherited, initialValue, interactive, internalShowDefaultValue, isMultiValue, isValueGettable, mapFallbackValue, messages, messages, originallyRequired, originalStringValues, parameterConsumer, paramLabel, preprocessor, prompt, renderedDescription, required, resetOriginalStringValues, resetStringValues, root, scope, scopeType, setter, setValue, setValue, showDefaultValue, splitRegex, splitRegexSynopsisLabel, stringValues, toString, type, typedValues, typeInfo, userObject
-
-
-
-
Method Detail
-
builder
public static CommandLine.Model.PositionalParamSpec.Builder builder()
-
builder
public static CommandLine.Model.PositionalParamSpec.Builder builder(CommandLine.Model.PositionalParamSpec original)
Returns a Builder initialized from the specifiedPositionalSpec.- Since:
- 4.0
-
builder
public static CommandLine.Model.PositionalParamSpec.Builder builder(CommandLine.Model.IAnnotatedElement source, CommandLine.IFactory factory)
-
toBuilder
public CommandLine.Model.PositionalParamSpec.Builder toBuilder()
Returns a new Builder initialized with the attributes from thisPositionalParamSpec. Callingbuildimmediately will return a copy of thisPositionalParamSpec.- Returns:
- a builder that can create a copy of this spec
-
isOption
public boolean isOption()
Description copied from class:CommandLine.Model.ArgSpecReturnstrueif this argument is a named option,falseotherwise.- Specified by:
isOptionin classCommandLine.Model.ArgSpec
-
isPositional
public boolean isPositional()
Description copied from class:CommandLine.Model.ArgSpecReturnstrueif this argument is a positional parameter,falseotherwise.- Specified by:
isPositionalin classCommandLine.Model.ArgSpec
-
getAdditionalDescriptionKeys
protected java.util.Collection<java.lang.String> getAdditionalDescriptionKeys()
Returns the additional lookup keys for finding description lines in the resource bundle for this positional parameter.- Specified by:
getAdditionalDescriptionKeysin classCommandLine.Model.ArgSpec- Returns:
- a collection with the following single value:
paramLabel() + "[" + index() + "]". - Since:
- 4.0
- See Also:
CommandLine.Model.OptionSpec.getAdditionalDescriptionKeys(),getAdditionalDescriptionKeys()
-
index
public CommandLine.Range index()
Returns an index or range specifying which of the command line arguments should be assigned to this positional parameter.- See Also:
CommandLine.Parameters.index()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-