public static class CommandLine.Model.OptionSpec.Builder extends Object
OptionSpec
objects.Modifier and Type | Method and Description |
---|---|
CommandLine.Range |
arity()
Returns how many arguments this option or positional parameter requires.
|
T |
arity(CommandLine.Range arity)
Sets how many arguments this option or positional parameter requires, and returns this builder.
|
T |
arity(String range)
Sets how many arguments this option or positional parameter requires, and returns this builder.
|
Class<?>[] |
auxiliaryTypes()
Returns auxiliary type information used when the
type() is a generic container like
Collection , Map , Optional or an abstract class. |
T |
auxiliaryTypes(Class<?>... types)
Sets auxiliary type information, and returns this builder.
|
CommandLine.Model.OptionSpec |
build()
Returns a valid
OptionSpec instance. |
Iterable<String> |
completionCandidates()
Returns the completion candidates for this option or positional parameter, or
null . |
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 more
type 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.
|
String |
fallbackValue()
Returns the fallback value for this option: the value that is assigned for options with an optional
parameter if the option was specified on the command line without parameter.
|
CommandLine.Model.OptionSpec.Builder |
fallbackValue(String fallbackValue)
Sets the fallback value for this option: the value that is assigned for options with an optional
parameter if the option was specified on the command line without parameter, and returns this builder.
|
CommandLine.Model.IGetter |
getter()
Returns the
CommandLine.Model.IGetter that is responsible for supplying the value of this argument. |
T |
getter(CommandLine.Model.IGetter getter)
Sets the
CommandLine.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 the
initialValue()
before parsing new input. |
T |
hasInitialValue(boolean hasInitialValue)
Determines whether the option or positional parameter will be reset to the
initialValue()
before parsing new input. |
boolean |
help()
Deprecated.
Use
usageHelp() and versionHelp() instead. |
CommandLine.Model.OptionSpec.Builder |
help(boolean help)
Sets whether this option disables validation of the other arguments, and returns this builder.
|
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.
|
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 . |
String[] |
names()
Returns one or more option names.
|
CommandLine.Model.OptionSpec.Builder |
names(String... names)
Replaces the option names with the specified values.
|
boolean |
negatable()
Returns whether a negative version for this boolean option is automatically added.
|
CommandLine.Model.OptionSpec.Builder |
negatable(boolean negatable)
Sets whether a negative version for this boolean option is automatically added, and returns this builder.
|
int |
order()
Returns the position in the options list in the usage help message at which this option should be shown.
|
CommandLine.Model.OptionSpec.Builder |
order(int order)
Sets the position in the options list in the usage help message at which this option should be shown, and returns this builder.
|
CommandLine.IParameterConsumer |
parameterConsumer()
Returns the custom parameter handler for this option or positional parameter, or
null . |
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 custom
IParameterPreprocessor to either replace or complement picocli's parsing logic
for the parameter(s) of this option or position, or null . |
T |
preprocessor(CommandLine.IParameterPreprocessor preprocessor)
Sets the custom
IParameterPreprocessor 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;
or
null 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 binding
CommandLine.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 binding
CommandLine.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.OptionSpec.Builder |
self()
Returns this builder.
|
CommandLine.Model.ISetter |
setter()
Returns the
CommandLine.Model.ISetter that is responsible for modifying the value of this argument. |
T |
setter(CommandLine.Model.ISetter setter)
Sets the
CommandLine.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.
|
boolean |
usageHelp()
Returns whether this option allows the user to request usage help.
|
CommandLine.Model.OptionSpec.Builder |
usageHelp(boolean usageHelp)
Sets whether this option allows the user to request usage help, 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.
|
boolean |
versionHelp()
Returns whether this option allows the user to request version information.
|
CommandLine.Model.OptionSpec.Builder |
versionHelp(boolean versionHelp)
Sets whether this option allows the user to request version information, 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.
|
public CommandLine.Model.OptionSpec build()
OptionSpec
instance.protected CommandLine.Model.OptionSpec.Builder self()
public String[] names()
CommandLine.Option.names()
@Deprecated public boolean help()
usageHelp()
and versionHelp()
instead.CommandLine.Option.help()
public boolean usageHelp()
CommandLine.Option.usageHelp()
public boolean versionHelp()
CommandLine.Option.versionHelp()
public boolean negatable()
CommandLine.INegatableOptionTransformer
.CommandLine.Option.negatable()
public String fallbackValue()
CommandLine.Option.fallbackValue()
public int order()
CommandLine.Model.UsageMessageSpec.sortOptions()
is false
for this command.CommandLine.Option.order()
public CommandLine.Model.OptionSpec.Builder names(String... names)
public CommandLine.Model.OptionSpec.Builder help(boolean help)
public CommandLine.Model.OptionSpec.Builder usageHelp(boolean usageHelp)
public CommandLine.Model.OptionSpec.Builder versionHelp(boolean versionHelp)
public CommandLine.Model.OptionSpec.Builder negatable(boolean negatable)
public CommandLine.Model.OptionSpec.Builder fallbackValue(String fallbackValue)
CommandLine.Option.fallbackValue()
public CommandLine.Model.OptionSpec.Builder order(int order)
public boolean required()
CommandLine.Option.required()
public boolean interactive()
CommandLine.Option.interactive()
public boolean echo()
CommandLine.Option.echo()
,
CommandLine.Parameters.echo()
public String prompt()
CommandLine.Option.prompt()
,
CommandLine.Parameters.prompt()
public String[] description()
CommandLine.Option.description()
public String descriptionKey()
CommandLine.Option.descriptionKey()
,
CommandLine.Parameters.descriptionKey()
public 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 container like
Collection
, Map
, Optional
or an abstract class.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()
Class
objects and be constructed both at runtime and compile timepublic 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()
null
means this option or positional parameter does not have a default.public Object initialValue()
hasInitialValue()
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.public boolean hasInitialValue()
initialValue()
before parsing new input.public CommandLine.Help.Visibility showDefaultValue()
public Iterable<String> completionCandidates()
null
.public CommandLine.IParameterConsumer parameterConsumer()
null
.public CommandLine.IParameterPreprocessor preprocessor()
IParameterPreprocessor
to either replace or complement picocli's parsing logic
for the parameter(s) of this option or position, or null
.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 the instance of the enclosing element where the setter sets the value (or the getter gets the value) of this argument.public CommandLine.ScopeType scopeType()
public T required(boolean required)
public T interactive(boolean interactive)
public T echo(boolean echo)
public T prompt(String prompt)
public T description(String... description)
CommandLine.Option.description()
public T descriptionKey(String descriptionKey)
CommandLine.Option.descriptionKey()
,
CommandLine.Parameters.descriptionKey()
public T arity(String range)
public T arity(CommandLine.Range arity)
public T paramLabel(String paramLabel)
public T hideParamSyntax(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 T auxiliaryTypes(Class<?>... types)
public T converters(CommandLine.ITypeConverter<?>... cs)
public T splitRegex(String splitRegex)
""
if the value should not be split, and returns this builder.public T splitRegexSynopsisLabel(String splitRegexSynopsisLabel)
public T showDefaultValue(CommandLine.Help.Visibility visibility)
public T completionCandidates(Iterable<String> completionCandidates)
public T parameterConsumer(CommandLine.IParameterConsumer parameterConsumer)
public T preprocessor(CommandLine.IParameterPreprocessor preprocessor)
IParameterPreprocessor
for this option or position, and returns this builder.public T hidden(boolean hidden)
public T inherited(boolean inherited)
public T root(CommandLine.Model.ArgSpec root)
public T type(Class<?> propertyType)
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.public T typeInfo(CommandLine.Model.ITypeInfo typeInfo)
typeInfo
- type information that does not require Class
objects and be constructed both at runtime and compile timepublic T userObject(Object userObject)
userObject
- may be the annotated program element, or some other useful objectpublic picocli.CommandLine.Model.ArgSpec.Builder mapFallbackValue(String fallbackValue)
-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.
CommandLine.Option.mapFallbackValue()
,
CommandLine.Parameters.mapFallbackValue()
public T defaultValue(String defaultValue)
null
or "__no_default_value__"
means no default.public T initialValue(Object initialValue)
hasInitialValue()
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.public T hasInitialValue(boolean hasInitialValue)
initialValue()
before parsing new input.public T getter(CommandLine.Model.IGetter getter)
CommandLine.Model.IGetter
that is responsible for getting the value of this argument, and returns this builder.public T setter(CommandLine.Model.ISetter setter)
CommandLine.Model.ISetter
that is responsible for modifying the value of this argument, and returns this builder.public T scope(CommandLine.Model.IScope scope)
CommandLine.Model.IScope
that targets where the setter sets the value, and returns this builder.public T scopeType(CommandLine.ScopeType scopeType)
public T withToString(String toString)