Package picocli
Class CommandLine.Model.PositionalParamSpec.Builder
- java.lang.Object
-
- picocli.CommandLine.Model.PositionalParamSpec.Builder
-
- Enclosing class:
- CommandLine.Model.PositionalParamSpec
public static class CommandLine.Model.PositionalParamSpec.Builder extends Object
Builder responsible for creating validPositionalParamSpec
objects.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandLine.Range
arity()
Returns how many arguments this option or positional parameter requires.T
arity(String range)
Sets how many arguments this option or positional parameter requires, and returns this builder.T
arity(CommandLine.Range arity)
Sets how many arguments this option or positional parameter requires, and returns this builder.Class<?>[]
auxiliaryTypes()
Returns auxiliary type information used when thetype()
is a generic container likeCollection
,Map
,Optional
or an abstract class.T
auxiliaryTypes(Class<?>... types)
Sets auxiliary type information, and returns this builder.CommandLine.Model.PositionalParamSpec
build()
Returns a validPositionalParamSpec
instance.Iterable<String>
completionCandidates()
Returns the completion candidates for this option or positional parameter, ornull
.T
completionCandidates(Iterable<String> completionCandidates)
Sets the completion candidates for this option or positional parameter, and returns this builder.CommandLine.ITypeConverter<?>[]
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).T
converters(CommandLine.ITypeConverter<?>... cs)
Sets option/positional param-specific converter (or converters for Maps), and returns this builder.String
defaultValue()
Returns the default value of this option or positional parameter, before splitting and type conversion.T
defaultValue(String defaultValue)
Sets the default value of this option or positional parameter to the specified value, and returns this builder.String[]
description()
Returns the description of this option, used when generating the usage documentation.T
description(String... description)
Sets the description of this option, used when generating the usage documentation, and returns this builder.String
descriptionKey()
Returns the description key of this arg spec, used to get the description from a resource bundle.T
descriptionKey(String descriptionKey)
Sets the description key that is used to look up the description in a resource bundle, and returns this builder.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.T
echo(boolean echo)
Sets whether the user input is echoed to the console or not for an interactive option or positional parameter.CommandLine.Model.IGetter
getter()
Returns theCommandLine.Model.IGetter
that is responsible for supplying the value of this argument.T
getter(CommandLine.Model.IGetter getter)
Sets theCommandLine.Model.IGetter
that is responsible for getting the value of this argument, and returns this builder.boolean
hasInitialValue()
Determines whether the option or positional parameter will be reset to theinitialValue()
before parsing new input.T
hasInitialValue(boolean hasInitialValue)
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.T
hidden(boolean hidden)
Sets whether this option should be excluded from the usage message, and returns this builder.boolean
hideParamSyntax()
Returns whether usage syntax decorations around the paramLabel should be suppressed.T
hideParamSyntax(boolean hideParamSyntax)
Sets whether usage syntax decorations around the paramLabel should be suppressed.CommandLine.Range
index()
Returns an index or range specifying which of the command line arguments should be assigned to this positional parameter.CommandLine.Model.PositionalParamSpec.Builder
index(String range)
Sets the index or range specifying which of the command line arguments should be assigned to this positional parameter, and returns this builder.CommandLine.Model.PositionalParamSpec.Builder
index(CommandLine.Range index)
Sets the index or range specifying which of the command line arguments should be assigned to this positional parameter, and returns this builder.boolean
inherited()
Returns whether this option is inherited from a parent command.T
inherited(boolean inherited)
Sets whether this option is inherited from a parent command, and returns this builder.Object
initialValue()
Returns the initial value this option or positional parameter.T
initialValue(Object initialValue)
Sets the initial value of this option or positional parameter to the specified value, and returns this builder.boolean
interactive()
Returns whether this option prompts the user to enter a value on the command line.T
interactive(boolean interactive)
Sets whether this option prompts the user to enter a value on the command line, and returns this builder.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
.picocli.CommandLine.Model.ArgSpec.Builder
mapFallbackValue(String fallbackValue)
Sets 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.IParameterConsumer
parameterConsumer()
Returns the custom parameter handler for this option or positional parameter, ornull
.T
parameterConsumer(CommandLine.IParameterConsumer parameterConsumer)
Sets the parameterConsumer for this option or positional parameter, and returns this builder.String
paramLabel()
Returns the name of the option or positional parameter used in the usage help message.T
paramLabel(String paramLabel)
Sets the name of the option or positional parameter used in the usage help message, and returns this builder.CommandLine.IParameterPreprocessor
preprocessor()
Returns the customIParameterPreprocessor
to either replace or complement picocli's parsing logic for the parameter(s) of this option or position, ornull
.T
preprocessor(CommandLine.IParameterPreprocessor preprocessor)
Sets the customIParameterPreprocessor
for this option or position, and returns this builder.String
prompt()
Returns the text displayed to the end user for an interactive option or positional parameter when asking for user input.T
prompt(String prompt)
Sets the text displayed to the end user for an interactive option or positional parameter when asking for user input.boolean
required()
Returns whether this is a required option or positional parameter.T
required(boolean required)
Sets whether this is a required option or positional parameter, and returns this builder.CommandLine.Model.ArgSpec
root()
Returns the root option or positional parameter (on the parent command), if this option or positional parameter was inherited; ornull
if it was not.T
root(CommandLine.Model.ArgSpec root)
Sets the root object for this inherited option, and returns this builder.CommandLine.Model.IScope
scope()
Returns the bindingCommandLine.Model.IScope
that determines the instance of the enclosing element where the setter sets the value (or the getter gets the value) of this argument.T
scope(CommandLine.Model.IScope scope)
Sets the bindingCommandLine.Model.IScope
that targets where the setter sets the value, and returns this builder.CommandLine.ScopeType
scopeType()
Returns the scope of this argument.T
scopeType(CommandLine.ScopeType scopeType)
Sets the scope of where this argument applies: only this command, or also all sub (and sub-sub) commands, and returns this builder.protected CommandLine.Model.PositionalParamSpec.Builder
self()
Returns this builder.CommandLine.Model.ISetter
setter()
Returns theCommandLine.Model.ISetter
that is responsible for modifying the value of this argument.T
setter(CommandLine.Model.ISetter setter)
Sets theCommandLine.Model.ISetter
that is responsible for modifying the value of this argument, and returns this builder.CommandLine.Help.Visibility
showDefaultValue()
Returns whether this option or positional parameter's default value should be shown in the usage help.T
showDefaultValue(CommandLine.Help.Visibility visibility)
Sets whether this option or positional parameter's default value should be shown in the usage help, and returns this builder.String
splitRegex()
Returns a regular expression to split option parameter values or""
if the value should not be split.T
splitRegex(String splitRegex)
Sets a regular expression to split option parameter values or""
if the value should not be split, and returns this builder.String
splitRegexSynopsisLabel()
Returns a regular expression to split option parameter for usage information.T
splitRegexSynopsisLabel(String splitRegexSynopsisLabel)
Sets a regular expression to split option parameter for usage information.String
toString()
Class<?>
type()
Returns the type to convert the option or positional parameter to before setting the value.T
type(Class<?> propertyType)
Sets the type to convert the option or positional parameter to before setting the value, and returns this builder.CommandLine.Model.ITypeInfo
typeInfo()
Returns the type info for this option or positional parameter.T
typeInfo(CommandLine.Model.ITypeInfo typeInfo)
Sets the type info for this option or positional parameter, and returns this builder.Object
userObject()
Returns the user object associated with this option or positional parameters.T
userObject(Object userObject)
Sets the user object associated with this option or positional parameters, and returns this builder.T
withToString(String toString)
Sets the string representation of this option or positional parameter to the specified value, and returns this builder.
-
-
-
Method Detail
-
build
public CommandLine.Model.PositionalParamSpec build()
Returns a validPositionalParamSpec
instance.
-
self
protected CommandLine.Model.PositionalParamSpec.Builder self()
Returns this builder.
-
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()
-
index
public CommandLine.Model.PositionalParamSpec.Builder index(String range)
Sets the index or range specifying which of the command line arguments should be assigned to this positional parameter, and returns this builder.
-
index
public CommandLine.Model.PositionalParamSpec.Builder index(CommandLine.Range index)
Sets the index or range specifying which of the command line arguments should be assigned to this positional parameter, and returns this builder.
-
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 prompts the user to enter a value on the command line.- See Also:
CommandLine.Option.interactive()
-
echo
public 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.- Since:
- 4.6
- See Also:
CommandLine.Option.echo()
,CommandLine.Parameters.echo()
-
prompt
public String prompt()
Returns the text displayed to the end user for an interactive option or positional parameter when asking for user input.- Since:
- 4.6
- See Also:
CommandLine.Option.prompt()
,CommandLine.Parameters.prompt()
-
description
public String[] description()
Returns the description of this option, used when generating the usage documentation.- 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()
-
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 generic container likeCollection
,Map
,Optional
or an abstract class.- See Also:
CommandLine.Option.type()
-
converters
public CommandLine.ITypeConverter<?>[] 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:
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()
-
splitRegexSynopsisLabel
public String splitRegexSynopsisLabel()
Returns a regular expression to split option parameter for usage information.- Since:
- 4.3
- See Also:
CommandLine.Option.splitSynopsisLabel()
-
hidden
public boolean hidden()
Returns whether this option should be excluded from the usage message.- See Also:
CommandLine.Option.hidden()
-
inherited
public boolean inherited()
Returns whether this option is inherited from a parent command.- Since:
- 4.3.0
- See Also:
CommandLine.Option.scope()
-
root
public CommandLine.Model.ArgSpec root()
Returns the root option or positional parameter (on the parent command), if this option or positional parameter was inherited; ornull
if it was not.- Since:
- 4.6.1
- See Also:
CommandLine.Option.scope()
-
type
public Class<?> type()
Returns the type to convert the option or positional parameter to before setting the value. This may be a container type likeList
,Map
, orOptional
, in which case the type or types of the elements are returned byauxiliaryTypes()
.
-
typeInfo
public CommandLine.Model.ITypeInfo typeInfo()
Returns the type info for this option or positional parameter.- Returns:
- type information that does not require
Class
objects and be constructed both at runtime and compile time - Since:
- 4.0
-
userObject
public Object 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
-
mapFallbackValue
public 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
.If no
mapFallbackValue
is set, key-only Map parameters like-Dkey
are considered invalid user input and cause aCommandLine.ParameterException
to be thrown.By default, this method returns a special "__unspecified__" value indicating that no
mapFallbackValue
was set.- Since:
- 4.6
- See Also:
CommandLine.Option.mapFallbackValue()
,CommandLine.Parameters.mapFallbackValue()
-
defaultValue
public String defaultValue()
Returns the default value of this option or positional parameter, before splitting and type conversion. A value ofnull
means this option or positional parameter does not have a default.
-
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.
-
completionCandidates
public Iterable<String> completionCandidates()
Returns the completion candidates for this option or positional parameter, ornull
.- Since:
- 3.2
-
parameterConsumer
public CommandLine.IParameterConsumer parameterConsumer()
Returns the custom parameter handler for this option or positional parameter, ornull
.- Since:
- 4.0
-
preprocessor
public CommandLine.IParameterPreprocessor preprocessor()
Returns the customIParameterPreprocessor
to either replace or complement picocli's parsing logic for the parameter(s) of this option or position, ornull
.- Since:
- 4.6
-
getter
public CommandLine.Model.IGetter getter()
Returns theCommandLine.Model.IGetter
that is responsible for supplying the value of this argument.
-
setter
public CommandLine.Model.ISetter setter()
Returns theCommandLine.Model.ISetter
that is responsible for modifying the value of this argument.
-
scope
public CommandLine.Model.IScope scope()
Returns the bindingCommandLine.Model.IScope
that determines the instance of the enclosing element where the setter sets the value (or the getter gets the value) of this argument.
-
scopeType
public CommandLine.ScopeType scopeType()
Returns the scope of this argument.- Returns:
- whether this argument applies to all descendent subcommands of the command where it is defined
- Since:
- 4.3
-
required
public T required(boolean required)
Sets whether this is a required option or positional parameter, and returns this builder.
-
interactive
public T interactive(boolean interactive)
Sets whether this option prompts the user to enter a value on the command line, and returns this builder.
-
echo
public T echo(boolean echo)
Sets whether the user input is echoed to the console or not for an interactive option or positional parameter.
-
prompt
public T prompt(String prompt)
Sets the text displayed to the end user for an interactive option or positional parameter when asking for user input.
-
description
public T description(String... description)
Sets the description of this option, used when generating the usage documentation, and returns this builder.- See Also:
CommandLine.Option.description()
-
descriptionKey
public T descriptionKey(String descriptionKey)
Sets the description key that is used to look up the description in a resource bundle, and returns this builder.- Since:
- 3.6
- See Also:
CommandLine.Option.descriptionKey()
,CommandLine.Parameters.descriptionKey()
-
arity
public T arity(String range)
Sets how many arguments this option or positional parameter requires, and returns this builder.
-
arity
public T arity(CommandLine.Range arity)
Sets how many arguments this option or positional parameter requires, and returns this builder.
-
paramLabel
public T paramLabel(String paramLabel)
Sets the name of the option or positional parameter used in the usage help message, and returns this builder.
-
hideParamSyntax
public T hideParamSyntax(boolean hideParamSyntax)
Sets 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 T auxiliaryTypes(Class<?>... types)
Sets auxiliary type information, and returns this builder.
-
converters
public T converters(CommandLine.ITypeConverter<?>... cs)
Sets option/positional param-specific converter (or converters for Maps), and returns this builder.
-
splitRegex
public T splitRegex(String splitRegex)
Sets a regular expression to split option parameter values or""
if the value should not be split, and returns this builder.
-
splitRegexSynopsisLabel
public T splitRegexSynopsisLabel(String splitRegexSynopsisLabel)
Sets a regular expression to split option parameter for usage information.
-
showDefaultValue
public T showDefaultValue(CommandLine.Help.Visibility visibility)
Sets whether this option or positional parameter's default value should be shown in the usage help, and returns this builder.
-
completionCandidates
public T completionCandidates(Iterable<String> completionCandidates)
Sets the completion candidates for this option or positional parameter, and returns this builder.- Since:
- 3.2
-
parameterConsumer
public T parameterConsumer(CommandLine.IParameterConsumer parameterConsumer)
Sets the parameterConsumer for this option or positional parameter, and returns this builder.- Since:
- 4.0
-
preprocessor
public T preprocessor(CommandLine.IParameterPreprocessor preprocessor)
Sets the customIParameterPreprocessor
for this option or position, and returns this builder.- Since:
- 4.6
-
hidden
public T hidden(boolean hidden)
Sets whether this option should be excluded from the usage message, and returns this builder.
-
inherited
public T inherited(boolean inherited)
Sets whether this option is inherited from a parent command, and returns this builder.- Since:
- 4.3.0
-
root
public T root(CommandLine.Model.ArgSpec root)
Sets the root object for this inherited option, and returns this builder.- Since:
- 4.6.1
-
type
public T type(Class<?> propertyType)
Sets the type to convert the option or positional parameter to before setting the value, and returns this builder.- Parameters:
propertyType
- the type of this option or parameter. For multi-value options and positional parameters this can be an array, or a (sub-type of) Collection or Map.
-
typeInfo
public T typeInfo(CommandLine.Model.ITypeInfo typeInfo)
Sets the type info for this option or positional parameter, and returns this builder.- Parameters:
typeInfo
- type information that does not requireClass
objects and be constructed both at runtime and compile time- Since:
- 4.0
-
userObject
public T userObject(Object userObject)
Sets the user object associated with this option or positional parameters, and returns this builder.- Parameters:
userObject
- may be the annotated program element, or some other useful object- Since:
- 4.0
-
mapFallbackValue
public picocli.CommandLine.Model.ArgSpec.Builder mapFallbackValue(String fallbackValue)
Sets 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
.If no
mapFallbackValue
is set, key-only Map parameters like-Dkey
are considered invalid user input and cause aCommandLine.ParameterException
to be thrown.- Since:
- 4.6
- See Also:
CommandLine.Option.mapFallbackValue()
,CommandLine.Parameters.mapFallbackValue()
-
defaultValue
public T defaultValue(String defaultValue)
Sets the default value of this option or positional parameter to the specified value, and returns this builder. Before parsing the command line, the result of splitting and type converting this default value is applied to the option or positional parameter. A value ofnull
or"__no_default_value__"
means no default.
-
initialValue
public T initialValue(Object initialValue)
Sets the initial value of this option or positional parameter to the specified value, and returns this builder. 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 T hasInitialValue(boolean hasInitialValue)
Determines whether the option or positional parameter will be reset to theinitialValue()
before parsing new input.
-
getter
public T getter(CommandLine.Model.IGetter getter)
Sets theCommandLine.Model.IGetter
that is responsible for getting the value of this argument, and returns this builder.
-
setter
public T setter(CommandLine.Model.ISetter setter)
Sets theCommandLine.Model.ISetter
that is responsible for modifying the value of this argument, and returns this builder.
-
scope
public T scope(CommandLine.Model.IScope scope)
Sets the bindingCommandLine.Model.IScope
that targets where the setter sets the value, and returns this builder.
-
scopeType
public T scopeType(CommandLine.ScopeType scopeType)
Sets the scope of where this argument applies: only this command, or also all sub (and sub-sub) commands, and returns this builder.- Since:
- 4.3
-
withToString
public T withToString(String toString)
Sets the string representation of this option or positional parameter to the specified value, and returns this builder.
-
-