Class CommandLine.Model.CommandSpec
- Enclosing class:
CommandLine.Model
CommandSpec class models a command specification, including the options, positional parameters and subcommands
supported by the command, as well as attributes for the version help message and the usage help message of the command.
Picocli views a command line application as a hierarchy of commands: there is a top-level command (usually the Java
class with the main method) with optionally a set of command line options, positional parameters and subcommands.
Subcommands themselves can have options, positional parameters and nested sub-subcommands to any level of depth.
The object model has a corresponding hierarchy of CommandSpec objects, each with a set of CommandLine.Model.OptionSpec,
CommandLine.Model.PositionalParamSpec and subcommands associated with it.
This object model is used by the picocli command line interpreter and help message generator.
Picocli can construct a CommandSpec automatically from classes with @Command, @Option and
@Parameters annotations. Alternatively a CommandSpec can be constructed programmatically.
- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<CommandLine.Model.ArgSpec> private CommandLineprivate final CommandLine.Model.CaseAwareLinkedMap<String, CommandLine> static final StringConstant String holding the default program name:"<main class>".(package private) static final BooleanConstant Boolean holding the default setting for whether variables should be interpolated in String values:.(package private) static final BooleanConstant Boolean holding the default setting for whether method commands should be added as subcommands:.(package private) static final BooleanConstant Boolean holding the default setting for whether this is a help command:.(package private) static final Booleanprivate Integerprivate Integerprivate Integerprivate Integerprivate Integerprivate final List<CommandLine.Model.ArgGroupSpec> private booleanprivate Booleanprivate final CommandLine.Model.Interpolatorprivate Booleanprivate Booleanprivate CommandLine.Model.TypedMember[]private final Map<String, CommandLine.Model.IAnnotatedElement> private final Map<String, CommandLine.Model.CommandSpec> private CommandLine.IModelTransformerprivate Stringprivate final List<CommandLine.Model.OptionSpec> private CommandLine.Model.CommandSpecprivate final List<CommandLine.Model.IAnnotatedElement> private final CommandLine.Model.ParserSpecprivate final List<CommandLine.Model.PositionalParamSpec> private final List<CommandLine.Model.ArgSpec> private CommandLine.ScopeTypeprivate final List<CommandLine.Model.IAnnotatedElement> private Booleanprivate Stringprivate final List<CommandLine.Model.UnmatchedArgsBinding> private final CommandLine.Model.UsageMessageSpecprivate final CommandLine.Model.CommandUserObjectprivate String[]private CommandLine.IVersionProvider -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateCommandSpec(CommandLine.Model.CommandUserObject userObject) -
Method Summary
Modifier and TypeMethodDescriptionAdds the specified option spec or positional parameter spec to the list of configured arguments to expect.private voidaddAlias(String alias, String name, CommandLine subCommandLine, CommandLine.Tracer t) private CommandLine.Model.CommandSpecAdds the specified argument group to the groups in this command.private CommandLine.Model.CommandSpecaddArgGroup(CommandLine.Model.ArgGroupSpec group, Set<CommandLine.Model.OptionSpec> groupOptions, Set<CommandLine.Model.PositionalParamSpec> groupPositionals) private voidaddGroupArgsToCommand(CommandLine.Model.ArgGroupSpec group, Map<String, CommandLine.Model.ArgGroupSpec> added, Set<CommandLine.Model.OptionSpec> groupOptions, Set<CommandLine.Model.PositionalParamSpec> groupPositionals) Reflects on the class of the user object and registers any command methods (class methods annotated with@Command) as subcommands.addMethodSubcommands(CommandLine.IFactory factory) Reflects on the class of the user object and registers any command methods (class methods annotated with@Command) as subcommands.addMixin(String name, CommandLine.Model.CommandSpec mixin) Adds the specified mixinCommandSpecobject to the map of mixins for this command.addMixin(String name, CommandLine.Model.CommandSpec mixin, CommandLine.Model.IAnnotatedElement annotatedElement) Adds the specified mixinCommandSpecobject to the map of mixins for this command.Adds the specified option spec to the list of configured arguments to expect.private voidaddOptionNegative(CommandLine.Model.OptionSpec option, CommandLine.Tracer tracer) Adds the specified{@literal @}ParentCommand-annotated program element to the list of elements for this command.addPositional(CommandLine.Model.PositionalParamSpec positional) Adds the specified positional parameter spec to the list of configured arguments to expect.Adds the specified{@literal @}Spec-annotated program element to the list of elements for this command.addSubcommand(String name, CommandLine subCommandLine) Adds the specified subcommand with the specified name.addSubcommand(String name, CommandLine.Model.CommandSpec subcommand) Adds the specified subcommand with the specified name.Adds the specifiedUnmatchedArgsBindingto the list of model objects to capture unmatched arguments for this command.private voidAdjusts the index of the new positional param and all others with relative indices that were sorted after this positional.String[]aliases()Returns the alias command names of this subcommand.Sets the alternative names by which this subcommand is recognized on the command line.Returns the argument groups in this command.args()Returns the list of all options and positional parameters configured for this command.private voidcheck(CommandLine.Model.ArgGroupSpec group, Set<CommandLine.Model.ArgGroupSpec> existing) Returns the CommandLine constructed with thisCommandSpecmodel.protected CommandLine.Model.CommandSpeccommandLine(CommandLine commandLine) Sets the CommandLine constructed with thisCommandSpecmodel.(package private) Object[]private CommandLine.Model.CommandSpeccopy()create()Creates and returns a newCommandSpecwithout any associated user object.(package private) static List<CommandLine> createMethodSubcommands(Class<?> cls, CommandLine.IFactory factory, boolean includeInherited) Returns the default value provider for this command.defaultValueProvider(CommandLine.IDefaultValueProvider defaultValueProvider) Sets default value provider for this command.intReturns exit code signifying that an exception occurred when invoking the Runnable, Callable or Method user object of a command.exitCodeOnExecutionException(int newValue) Sets exit code signifying that an exception occurred when invoking the Runnable, Callable or Method user object of a command.intReturns exit code for command line usage error.exitCodeOnInvalidInput(int newValue) Sets exit code for command line usage error.intReturns exit code for successful termination.exitCodeOnSuccess(int newValue) Sets exit code for successful termination.intReturns exit code for successful termination after printing usage help on user request.exitCodeOnUsageHelp(int newValue) Sets exit code for successful termination after printing usage help on user request.intReturns exit code for successful termination after printing version help on user request.exitCodeOnVersionHelp(int newValue) Sets exit code for successful termination after printing version help on user request.findOption(char shortName) Returns the option with the specified short name, ornullif no option with that name is defined for this command.(package private) static CommandLine.Model.OptionSpecfindOption(char shortName, Iterable<CommandLine.Model.OptionSpec> options) findOption(String name) Returns the option with the specified name, ornullif no option with that name is defined for this command.(package private) static CommandLine.Model.OptionSpecfindOption(String name, List<CommandLine.Model.OptionSpec> options) private Set<CommandLine.Model.ArgGroupSpec> flatten(Collection<CommandLine.Model.ArgGroupSpec> groups, Set<CommandLine.Model.ArgGroupSpec> result) private Set<CommandLine.Model.ArgGroupSpec> flatten(CommandLine.Model.ArgGroupSpec group, Set<CommandLine.Model.ArgGroupSpec> result) forAnnotatedObject(Object userObject) Creates and returns a newCommandSpecinitialized from the specified associated user object.forAnnotatedObject(Object userObject, CommandLine.IFactory factory) Creates and returns a newCommandSpecinitialized from the specified associated user object.forAnnotatedObjectLenient(Object userObject) Creates and returns a newCommandSpecinitialized from the specified associated user object.forAnnotatedObjectLenient(Object userObject, CommandLine.IFactory factory) Creates and returns a newCommandSpecinitialized from the specified associated user object.booleanReturns whether this subcommand is a help command, and required options and positional parameters of the parent command should not be validated.helpCommand(boolean newValue) Sets whether this is a help command and required parameter checking should be suspended.private voidbooleanReturns whether this command is inherited from a parent command.(package private) voidinitAliases(String[] aliases) private voidinitCommandHierarchyWithResourceBundle(String bundleBaseName, ResourceBundle rb) (package private) voidinitDefaultValueProvider(Class<? extends CommandLine.IDefaultValueProvider> value, CommandLine.IFactory factory) (package private) void(package private) voidinitExitCodeOnExecutionException(int exitCode) (package private) voidinitExitCodeOnInvalidInput(int exitCode) (package private) voidinitExitCodeOnSuccess(int exitCode) (package private) voidinitExitCodeOnUsageHelp(int exitCode) (package private) voidinitExitCodeOnVersionHelp(int exitCode) private void(package private) voidinitHelpCommand(boolean value) (package private) void(package private) void(package private) void(package private) voidinitSubcommandsRepeatable(boolean value) (package private) voidinitVersion(String[] value) (package private) void(package private) voidinjectParentCommand(CommandLine.Model.CommandUserObject commandUserObject) booleanReturns whether variables should be interpolated in String values.interpolateVariables(Boolean interpolate) Sets whether variables should be interpolated in String values.booleanReturns whether method commands should be added as subcommands.Returns a map of the mixin names to mixinIAnnotatedElementobjects for this command.mixins()Returns a map of the mixin names to mixinCommandSpecobjects configured for this command.booleanReturnstrueif the standard help options have been mixed in with this command,falseotherwise.mixinStandardHelpOptions(boolean newValue) Sets whether the standard help options should be mixed in with this command.Returns the model transformer for this CommandSpec instance.modelTransformer(CommandLine.IModelTransformer modelTransformer) Sets the model transformer for this CommandSpec instance.name()Returns name of this command.Sets the String to use as the program name in the synopsis line of the help message.names()Returns theINegatableOptionTransformerused to create the negative form of negatable options.Sets theINegatableOptionTransformerused to create the negative form of negatable options.Returns a map of the negated option names to option spec objects configured for this command.options()Returns the list of options configured for this command.booleanReturns whether the options are case-insensitive.optionsCaseInsensitive(boolean caseInsensitiveOptions) Sets the case-insensitivity of options.Returns a map of the option names to option spec objects configured for this command.parent()Returns the parent command of this subcommand, ornullif this is a top-level command.parent(CommandLine.Model.CommandSpec parent) Sets the parent command of this subcommand.Returns the list of program elements annotated with{@literal @}ParentCommandconfigured for this command.parser()Returns the parser specification for this command.parser(CommandLine.Model.ParserSpec settings) Initializes the parser specification for this command from the specified settings and returns this commandSpec.Returns the list of positional parameters configured for this command.Returns a map of the short (single character) option names to option spec objects configured for this command.Returns the preprocessor for this CommandSpec instance.preprocessor(CommandLine.IParameterPreprocessor preprocessor) Sets the preprocessor for this CommandSpec instance.Returns the String to use as the program name in the synopsis line of the help message: this command'sname, preceded by the qualified name of the parent command, if any, separated by a space.qualifiedName(String separator) Returns this command's fully qualified name, which is itsname, preceded by the qualified name of the parent command, if this command has a parent command.(INCUBATING) Removes the specified option spec or positional parameter spec from the list of configured arguments to expect.private static <T> intremove(CommandLine.Model.ArgSpec arg, Map<T, CommandLine.Model.OptionSpec> map) private voidremoveAlias(String alias, CommandLine subCommandLine, CommandLine.Tracer t) removeSubcommand(String name) Removes the subcommand with the specified name or alias from this CommandSpec and returns theCommandLineinstance that was associated with the specified name, ornullof the specified name was not associated with a subcommand.Returns the list of required options and positional parameters configured for this command.(package private) booleanresemblesOption(String arg) private voidReturns the resource bundle for this command.resourceBundle(ResourceBundle bundle) Initializes the resource bundle for this command: sets theUsageMessageSpec.messagesto aMessagesobject created from this command spec and the specified bundle, and then sets theArgSpec.messagesof all options and positional parameters in this command to the sameMessagesinstance.Returns the resource bundle base name for this command.resourceBundleBaseName(String resourceBundleBaseName) Initializes the resource bundle for this command: sets theUsageMessageSpec.messagesto aMessagesobject created from this command spec and the specified bundle, and then sets theArgSpec.messagesof all options and positional parameters in this command to the sameMessagesinstance.root()Returns the root command: the top-level command of the hierarchy, nevernull.Returns the scope of this argument; is it local, or inherited (it applies to this command as well as all sub- and sub-subcommands).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.setAddMethodSubcommands(Boolean addMethodSubcommands) Sets whether method commands should be added as subcommands.private voidsetBundle(String bundleBaseName, ResourceBundle bundle) private voidReturns the list of program elements annotated with{@literal @}Specconfigured for this command.(package private) static StringstripPrefix(String prefixed) Returns a read-only view of the subcommand map.booleanReturns whether the subcommands are case-insensitive.subcommandsCaseInsensitive(boolean caseInsensitiveSubcommands) Sets the case-insensitivity of subcommands.booleanReturns whether the subcommands of this command are repeatable, that is, whether such subcommands can occur multiple times and may be followed by sibling commands instead of just child commands.subcommandsRepeatable(boolean subcommandsRepeatable) Sets whether the subcommands of this command are repeatable, that is, whether such subcommands can occur multiple times and may be followed by sibling commands instead of just child commands.toString()Returns a string representation of this command, used in error messages and trace messages.Returns the list ofUnmatchedArgumentsBindingsconfigured for this command; eachUnmatchedArgsBindingcaptures the arguments that could not be matched to any options or positional parameters.(package private) voidupdateAddMethodSubcommands(boolean value) private voidvoidupdateCommandAttributes(CommandLine.Command cmd, CommandLine.IFactory factory) Updates the following attributes from the specified@Commandannotation: aliases,parser separator, command name, version, help command, version provider, default provider andusage message spec.private void(package private) voidupdateExitCodeOnExecutionException(int exitCode) (package private) voidupdateExitCodeOnInvalidInput(int exitCode) (package private) voidupdateExitCodeOnSuccess(int exitCode) (package private) voidupdateExitCodeOnUsageHelp(int exitCode) (package private) voidupdateExitCodeOnVersionHelp(int exitCode) (package private) voidupdateHelpCommand(boolean value) (package private) voidupdateModelTransformer(Class<? extends CommandLine.IModelTransformer> value, CommandLine.IFactory factory) (package private) voidupdateName(String value) (package private) voidupdatePreprocessor(Class<? extends CommandLine.IParameterPreprocessor> value, CommandLine.IFactory factory) (package private) voidupdateScopeType(CommandLine.ScopeType scopeType) (package private) voidupdateSubcommandsRepeatable(boolean value) (package private) voidupdateVersion(String[] value) (package private) voidupdateVersionProvider(Class<? extends CommandLine.IVersionProvider> value, CommandLine.IFactory factory) Returns the usage help message specification for this command.Initializes the usageMessage specification for this command from the specified settings and returns this commandSpec.Returns the user object associated with this command.(package private) voidvalidate()Ensures all attributes of thisCommandSpechave a valid value; throws anCommandLine.InitializationExceptionif this cannot be achieved.private StringvalidateSubcommandName(String name, CommandLine.Model.CommandSpec subSpec) String[]version()Returns version information for this command, to print to the console when the user specifies an option to request version help.Sets version information literals for this command, to print to the console when the user specifies an option to request version help.Returns the version provider for this command, to generate theversion()strings.versionProvider(CommandLine.IVersionProvider versionProvider) Sets version provider for this command, to generate theversion()strings.withToString(String newValue) Sets the string representation of this command, used in error messages and trace messages.wrapWithoutInspection(Object userObject) Creates and returns a newCommandSpecwith the specified associated user object.wrapWithoutInspection(Object userObject, CommandLine.IFactory factory) Creates and returns a newCommandSpecwith the specified associated user object.
-
Field Details
-
DEFAULT_COMMAND_NAME
Constant String holding the default program name:"<main class>".- Since:
- 4.0
- See Also:
-
DEFAULT_IS_HELP_COMMAND
Constant Boolean holding the default setting for whether this is a help command:. -
DEFAULT_IS_ADD_METHOD_SUBCOMMANDS
Constant Boolean holding the default setting for whether method commands should be added as subcommands:. -
DEFAULT_INTERPOLATE_VARIABLES
Constant Boolean holding the default setting for whether variables should be interpolated in String values:. -
DEFAULT_SUBCOMMANDS_REPEATABLE
-
commands
-
optionsByNameMap
private final CommandLine.Model.CaseAwareLinkedMap<String,CommandLine.Model.OptionSpec> optionsByNameMap -
negatedOptionsByNameMap
private final CommandLine.Model.CaseAwareLinkedMap<String,CommandLine.Model.OptionSpec> negatedOptionsByNameMap -
posixOptionsByKeyMap
private final CommandLine.Model.CaseAwareLinkedMap<Character,CommandLine.Model.OptionSpec> posixOptionsByKeyMap -
mixins
-
mixinAnnotatedElements
-
requiredArgs
-
args
-
options
-
positionalParameters
-
unmatchedArgs
-
specElements
-
parentCommandElements
-
groups
-
parser
-
interpolator
-
usageMessage
-
methodParams
-
userObject
-
commandLine
-
parent
-
isAddMethodSubcommands
-
interpolateVariables
-
name
-
aliases
-
isHelpCommand
-
versionProvider
-
defaultValueProvider
-
negatableOptionTransformer
-
subcommandsRepeatable
-
version
-
toString
-
inherited
private boolean inherited -
scopeType
-
exitCodeOnSuccess
-
exitCodeOnUsageHelp
-
exitCodeOnVersionHelp
-
exitCodeOnInvalidInput
-
exitCodeOnExecutionException
-
modelTransformer
-
preprocessor
-
-
Constructor Details
-
CommandSpec
-
-
Method Details
-
copy
-
create
Creates and returns a newCommandSpecwithout any associated user object. -
wrapWithoutInspection
Creates and returns a newCommandSpecwith the specified associated user object. The specified user object is not inspected for annotations.- Parameters:
userObject- the associated user object. May be any object, may benull.
-
wrapWithoutInspection
public static CommandLine.Model.CommandSpec wrapWithoutInspection(Object userObject, CommandLine.IFactory factory) Creates and returns a newCommandSpecwith the specified associated user object. The specified user object is not inspected for annotations.- Parameters:
userObject- the associated user object. May be any object, may benull.factory- the factory used to create instances of subcommands, converters, etc., that are registered declaratively with annotation attributes- Since:
- 4.2
-
forAnnotatedObject
Creates and returns a newCommandSpecinitialized from the specified associated user object. The specified user object must have at least oneCommandLine.Command,CommandLine.OptionorCommandLine.Parametersannotation.- Parameters:
userObject- the user object annotated withCommandLine.Command,CommandLine.Optionand/orCommandLine.Parametersannotations.- Throws:
CommandLine.InitializationException- if the specified object has no picocli annotations or has invalid annotations
-
forAnnotatedObject
public static CommandLine.Model.CommandSpec forAnnotatedObject(Object userObject, CommandLine.IFactory factory) Creates and returns a newCommandSpecinitialized from the specified associated user object. The specified user object must have at least oneCommandLine.Command,CommandLine.OptionorCommandLine.Parametersannotation.- Parameters:
userObject- the user object annotated withCommandLine.Command,CommandLine.Optionand/orCommandLine.Parametersannotations.factory- the factory used to create instances of subcommands, converters, etc., that are registered declaratively with annotation attributes- Throws:
CommandLine.InitializationException- if the specified object has no picocli annotations or has invalid annotations
-
forAnnotatedObjectLenient
Creates and returns a newCommandSpecinitialized from the specified associated user object. If the specified user object has noCommandLine.Command,CommandLine.OptionorCommandLine.Parametersannotations, an emptyCommandSpecis returned.- Parameters:
userObject- the user object annotated withCommandLine.Command,CommandLine.Optionand/orCommandLine.Parametersannotations.- Throws:
CommandLine.InitializationException- if the specified object has invalid annotations
-
forAnnotatedObjectLenient
public static CommandLine.Model.CommandSpec forAnnotatedObjectLenient(Object userObject, CommandLine.IFactory factory) Creates and returns a newCommandSpecinitialized from the specified associated user object. If the specified user object has noCommandLine.Command,CommandLine.OptionorCommandLine.Parametersannotations, an emptyCommandSpecis returned.- Parameters:
userObject- the user object annotated withCommandLine.Command,CommandLine.Optionand/orCommandLine.Parametersannotations.factory- the factory used to create instances of subcommands, converters, etc., that are registered declaratively with annotation attributes- Throws:
CommandLine.InitializationException- if the specified object has invalid annotations
-
validate
void validate()Ensures all attributes of thisCommandSpechave a valid value; throws anCommandLine.InitializationExceptionif this cannot be achieved. -
userObject
Returns the user object associated with this command.- See Also:
-
commandLine
Returns the CommandLine constructed with thisCommandSpecmodel. -
commandLine
Sets the CommandLine constructed with thisCommandSpecmodel. -
parser
Returns the parser specification for this command. -
parser
Initializes the parser specification for this command from the specified settings and returns this commandSpec. -
usageMessage
Returns the usage help message specification for this command. -
usageMessage
Initializes the usageMessage specification for this command from the specified settings and returns this commandSpec. -
subcommandsCaseInsensitive
public boolean subcommandsCaseInsensitive()Returns whether the subcommands are case-insensitive.- Since:
- 4.3
-
subcommandsCaseInsensitive
Sets the case-insensitivity of subcommands.- Since:
- 4.3
-
optionsCaseInsensitive
public boolean optionsCaseInsensitive()Returns whether the options are case-insensitive.- Since:
- 4.3
-
optionsCaseInsensitive
Sets the case-insensitivity of options. Note that changing case sensitivity will also change the case sensitivity of negatable options: any customCommandLine.INegatableOptionTransformerthat was previously installed will be replaced by the case-insensitive version of the default transformer. To ensure your custom transformer is used, install it last, after changing case sensitivity.- Since:
- 4.3
-
resourceBundleBaseName
Returns the resource bundle base name for this command.- Returns:
- the resource bundle base name from the CommandLine.Model.UsageMessageSpec.messages()
- Since:
- 4.0
-
resourceBundleBaseName
Initializes the resource bundle for this command: sets theUsageMessageSpec.messagesto aMessagesobject created from this command spec and the specified bundle, and then sets theArgSpec.messagesof all options and positional parameters in this command to the sameMessagesinstance. Subcommands are not modified.This method is preferable to
resourceBundle(ResourceBundle)for pre-Java 8- Parameters:
resourceBundleBaseName- the base name of the ResourceBundle to set, may benull- Returns:
- this commandSpec
- Since:
- 4.0
- See Also:
-
resourceBundle
Returns the resource bundle for this command.- Returns:
- the resource bundle from the CommandLine.Model.UsageMessageSpec.messages()
- Since:
- 3.6
-
resourceBundle
Initializes the resource bundle for this command: sets theUsageMessageSpec.messagesto aMessagesobject created from this command spec and the specified bundle, and then sets theArgSpec.messagesof all options and positional parameters in this command to the sameMessagesinstance. Subcommands are not modified.- Parameters:
bundle- the ResourceBundle to set, may benull- Returns:
- this commandSpec
- Since:
- 3.6
- See Also:
-
setBundle
-
updateArgSpecMessages
private void updateArgSpecMessages() -
subcommands
Returns a read-only view of the subcommand map. -
addSubcommand
public CommandLine.Model.CommandSpec addSubcommand(String name, CommandLine.Model.CommandSpec subcommand) Adds the specified subcommand with the specified name. If the specified subcommand does not have a ResourceBundle set, it is initialized to the ResourceBundle of this command spec.- Parameters:
name- subcommand name - the preferred subcommand name to register the subcommand under. Ifnull, the name of the specified subcommand is used; if this is alsonull, the first alias is used. When this String is encountered in the command line arguments, the subcommand is invoked.subcommand- describes the subcommand to envoke when the name is encountered on the command line- Returns:
- this
CommandSpecobject for method chaining - Throws:
CommandLine.InitializationException- if the specified name isnull, and no alternative name could be found, or if another subcommand was already registered under the same name, or if one of the aliases of the specified subcommand was already used by another subcommand.
-
addSubcommand
Adds the specified subcommand with the specified name. If the specified subcommand does not have a ResourceBundle set, it is initialized to the ResourceBundle of this command spec.- Parameters:
name- subcommand name - the preferred subcommand name to register the subcommand under. Ifnull, the name of the specified subcommand is used; if this is alsonull, the first alias is used. When this String is encountered in the command line arguments, the subcommand is invoked.subCommandLine- the subcommand to envoke when the name is encountered on the command line- Returns:
- this
CommandSpecobject for method chaining - Throws:
CommandLine.InitializationException- if the specified name isnull, and no alternative name could be found, or if another subcommand was already registered under the same name, or if one of the aliases of the specified subcommand was already used by another subcommand.
-
addAlias
-
removeAlias
-
inheritAttributesFrom
-
setInheritedDeep
private void setInheritedDeep() -
updatedSubcommandsToInheritFrom
-
removeSubcommand
Removes the subcommand with the specified name or alias from this CommandSpec and returns theCommandLineinstance that was associated with the specified name, ornullof the specified name was not associated with a subcommand.- Parameters:
name- name or alias of the subcommand to remove; may beabbreviatedorcase-insensitive- Returns:
- the removed
CommandLineinstance ornull - Since:
- 4.6
-
validateSubcommandName
-
initCommandHierarchyWithResourceBundle
-
isAddMethodSubcommands
public boolean isAddMethodSubcommands()Returns whether method commands should be added as subcommands. True by default. Used by the annotation processor.- Since:
- 4.0
-
setAddMethodSubcommands
Sets whether method commands should be added as subcommands. True by default. Used by the annotation processor.- Since:
- 4.0
-
interpolateVariables
public boolean interpolateVariables()Returns whether variables should be interpolated in String values. True by default.- Since:
- 4.0
-
interpolateVariables
Sets whether variables should be interpolated in String values. True by default.- Since:
- 4.0
-
addMethodSubcommands
Reflects on the class of the user object and registers any command methods (class methods annotated with@Command) as subcommands.- Returns:
- this
CommandLine.Model.CommandSpecobject for method chaining - Since:
- 3.6.0
- See Also:
-
addMethodSubcommands
Reflects on the class of the user object and registers any command methods (class methods annotated with@Command) as subcommands.- Parameters:
factory- the factory used to create instances of subcommands, converters, etc., that are registered declaratively with annotation attributes- Returns:
- this
CommandLine.Model.CommandSpecobject for method chaining - Since:
- 3.7.0
- See Also:
-
createMethodSubcommands
static List<CommandLine> createMethodSubcommands(Class<?> cls, CommandLine.IFactory factory, boolean includeInherited) -
parent
Returns the parent command of this subcommand, ornullif this is a top-level command. -
root
Returns the root command: the top-level command of the hierarchy, nevernull.- Since:
- 4.3
-
parent
Sets the parent command of this subcommand.- Returns:
- this CommandSpec for method chaining
-
add
Adds the specified option spec or positional parameter spec to the list of configured arguments to expect.- Parameters:
arg- the option spec or positional parameter spec to add- Returns:
- this CommandSpec for method chaining
-
addOption
Adds the specified option spec to the list of configured arguments to expect. The option's CommandLine.Model.ArgSpec.description() may now return Strings from this CommandSpec's messages. The option parameter's CommandLine.Model.ArgSpec.defaultValueString() may now return Strings from this CommandSpec'sdefaultValueProvider()IDefaultValueProvider}.- Parameters:
option- the option spec to add- Returns:
- this CommandSpec for method chaining
- Throws:
CommandLine.DuplicateOptionAnnotationsException- if any of the names of the specified option is the same as the name of another option
-
addOptionNegative
-
resetNegativeOptionNames
private void resetNegativeOptionNames() -
addPositional
public CommandLine.Model.CommandSpec addPositional(CommandLine.Model.PositionalParamSpec positional) Adds the specified positional parameter spec to the list of configured arguments to expect. The positional parameter's CommandLine.Model.ArgSpec.description() may now return Strings from this CommandSpec's messages. The positional parameter's CommandLine.Model.ArgSpec.defaultValueString() may now return Strings from this CommandSpec'sdefaultValueProvider()IDefaultValueProvider}.- Parameters:
positional- the positional parameter spec to add- Returns:
- this CommandSpec for method chaining
-
adjustRelativeIndices
Adjusts the index of the new positional param and all others with relative indices that were sorted after this positional.- Parameters:
newlyAdded- the newly added positional parameter
-
addArg
-
remove
(INCUBATING) Removes the specified option spec or positional parameter spec from the list of configured arguments to expect.- Parameters:
arg- the option spec or positional parameter spec to remove- Returns:
- this CommandSpec for method chaining
- Throws:
UnsupportedOperationException- if the specified ArgSpec is part of aCommandLine.Model.ArgGroupSpecNoSuchElementException- if the specified ArgSpec is not part of thisCommandSpec- Since:
- 4.0
-
remove
private static <T> int remove(CommandLine.Model.ArgSpec arg, Map<T, CommandLine.Model.OptionSpec> map) -
addArgGroup
Adds the specified argument group to the groups in this command.- Parameters:
group- the group spec to add- Returns:
- this CommandSpec for method chaining
- Throws:
CommandLine.InitializationException- if the specified group or one of its ancestors has already been added- Since:
- 4.0
-
addArgGroup
private CommandLine.Model.CommandSpec addArgGroup(CommandLine.Model.ArgGroupSpec group, Set<CommandLine.Model.OptionSpec> groupOptions, Set<CommandLine.Model.PositionalParamSpec> groupPositionals) -
addGroupArgsToCommand
private void addGroupArgsToCommand(CommandLine.Model.ArgGroupSpec group, Map<String, CommandLine.Model.ArgGroupSpec> added, Set<CommandLine.Model.OptionSpec> groupOptions, Set<CommandLine.Model.PositionalParamSpec> groupPositionals) -
flatten
private Set<CommandLine.Model.ArgGroupSpec> flatten(Collection<CommandLine.Model.ArgGroupSpec> groups, Set<CommandLine.Model.ArgGroupSpec> result) -
flatten
private Set<CommandLine.Model.ArgGroupSpec> flatten(CommandLine.Model.ArgGroupSpec group, Set<CommandLine.Model.ArgGroupSpec> result) -
check
private void check(CommandLine.Model.ArgGroupSpec group, Set<CommandLine.Model.ArgGroupSpec> existing) -
addMixin
public CommandLine.Model.CommandSpec addMixin(String name, CommandLine.Model.CommandSpec mixin, CommandLine.Model.IAnnotatedElement annotatedElement) Adds the specified mixinCommandSpecobject to the map of mixins for this command.- Parameters:
name- the name that can be used to later retrieve the mixinmixin- the mixin whose options and positional parameters and other attributes to add to this commandannotatedElement- the `@Mixin`-annotated program element- Returns:
- this CommandSpec for method chaining
- Since:
- 4.1
- See Also:
-
addMixin
Adds the specified mixinCommandSpecobject to the map of mixins for this command.- Parameters:
name- the name that can be used to later retrieve the mixinmixin- the mixin whose options and positional parameters and other attributes to add to this command- Returns:
- this CommandSpec for method chaining
-
initFrom
-
addUnmatchedArgsBinding
public CommandLine.Model.CommandSpec addUnmatchedArgsBinding(CommandLine.Model.UnmatchedArgsBinding spec) Adds the specifiedUnmatchedArgsBindingto the list of model objects to capture unmatched arguments for this command.- Parameters:
spec- the unmatched arguments binding to capture unmatched arguments- Returns:
- this CommandSpec for method chaining
-
addSpecElement
Adds the specified{@literal @}Spec-annotated program element to the list of elements for this command.- Returns:
- this CommandSpec for method chaining
- Since:
- 4.0
-
addParentCommandElement
public CommandLine.Model.CommandSpec addParentCommandElement(CommandLine.Model.IAnnotatedElement spec) Adds the specified{@literal @}ParentCommand-annotated program element to the list of elements for this command.- Returns:
- this CommandSpec for method chaining
- Since:
- 4.0
-
injectParentCommand
-
mixins
Returns a map of the mixin names to mixinCommandSpecobjects configured for this command.- Returns:
- an immutable map of mixins added to this command.
-
mixinAnnotatedElements
Returns a map of the mixin names to mixinIAnnotatedElementobjects for this command.- Returns:
- an immutable map of `@Mixin`-annotated elements added to this command.
- Since:
- 4.1
- See Also:
-
options
Returns the list of options configured for this command.- Returns:
- an immutable list of options that this command recognizes.
-
positionalParameters
Returns the list of positional parameters configured for this command.- Returns:
- an immutable list of positional parameters that this command recognizes.
-
argGroups
Returns the argument groups in this command.- Returns:
- an immutable list of groups of options and positional parameters in this command
- Since:
- 4.0
-
optionsMap
Returns a map of the option names to option spec objects configured for this command.- Returns:
- an immutable map of options that this command recognizes.
-
negatedOptionsMap
Returns a map of the negated option names to option spec objects configured for this command.- Returns:
- an immutable map of negatable options that this command recognizes.
- Since:
- 4.0
-
posixOptionsMap
Returns a map of the short (single character) option names to option spec objects configured for this command.- Returns:
- an immutable map of options that this command recognizes.
-
requiredArgs
Returns the list of required options and positional parameters configured for this command. This does not include options and positional parameters that are part of a group.- Returns:
- an immutable list of the required options and positional parameters for this command.
-
unmatchedArgsBindings
Returns the list ofUnmatchedArgumentsBindingsconfigured for this command; eachUnmatchedArgsBindingcaptures the arguments that could not be matched to any options or positional parameters. -
specElements
Returns the list of program elements annotated with{@literal @}Specconfigured for this command.- Since:
- 4.0
-
parentCommandElements
Returns the list of program elements annotated with{@literal @}ParentCommandconfigured for this command.- Since:
- 4.0
-
name
Returns name of this command. Used in the synopsis line of the help message.DEFAULT_COMMAND_NAMEby default, initialized fromCommandLine.Command.name()if defined.- See Also:
-
aliases
Returns the alias command names of this subcommand.- Since:
- 3.1
-
names
- Since:
- 3.9
-
args
Returns the list of all options and positional parameters configured for this command.- Returns:
- an immutable list of all options and positional parameters for this command.
-
commandMethodParamValues
Object[] commandMethodParamValues() -
qualifiedName
Returns the String to use as the program name in the synopsis line of the help message: this command'sname, preceded by the qualified name of the parent command, if any, separated by a space.- Returns:
DEFAULT_COMMAND_NAMEby default, initialized fromCommandLine.Command.name()and the parent command if defined.- Since:
- 3.0.1
-
qualifiedName
Returns this command's fully qualified name, which is itsname, preceded by the qualified name of the parent command, if this command has a parent command.- Parameters:
separator- the string to put between the names of the commands in the hierarchy- Returns:
DEFAULT_COMMAND_NAMEby default, initialized fromCommandLine.Command.name()and the parent command if any.- Since:
- 3.6
-
version
Returns version information for this command, to print to the console when the user specifies an option to request version help. This is not part of the usage help message.- Returns:
- the version strings generated by the
version providerif one is set, otherwise the version literals
-
versionProvider
Returns the version provider for this command, to generate theversion()strings.- Returns:
- the version provider or
nullif the version strings should be returned from the version literals.
-
helpCommand
public boolean helpCommand()Returns whether this subcommand is a help command, and required options and positional parameters of the parent command should not be validated.- Returns:
trueif this subcommand is a help command and picocli should not check for missing required options and positional parameters on the parent command- See Also:
-
exitCodeOnSuccess
public int exitCodeOnSuccess()Returns exit code for successful termination. 0 by default, may be set programmatically or via theexitCodeOnSuccessannotation.- Since:
- 4.0
- See Also:
-
exitCodeOnUsageHelp
public int exitCodeOnUsageHelp()Returns exit code for successful termination after printing usage help on user request. 0 by default, may be set programmatically or via theexitCodeOnVersionHelpannotation.- Since:
- 4.0
- See Also:
-
exitCodeOnVersionHelp
public int exitCodeOnVersionHelp()Returns exit code for successful termination after printing version help on user request. 0 by default, may be set programmatically or via theexitCodeOnUsageHelpannotation.- Since:
- 4.0
- See Also:
-
exitCodeOnInvalidInput
public int exitCodeOnInvalidInput()Returns exit code for command line usage error. 2 by default, may be set programmatically or via theexitCodeOnInvalidInputannotation.- Since:
- 4.0
- See Also:
-
exitCodeOnExecutionException
public int exitCodeOnExecutionException()Returns exit code signifying that an exception occurred when invoking the Runnable, Callable or Method user object of a command. 1 by default, may be set programmatically or via theexitCodeOnExecutionExceptionannotation.- Since:
- 4.0
- See Also:
-
negatableOptionTransformer
Returns theINegatableOptionTransformerused to create the negative form of negatable options.- Since:
- 4.0
- See Also:
-
mixinStandardHelpOptions
public boolean mixinStandardHelpOptions()Returnstrueif the standard help options have been mixed in with this command,falseotherwise. -
subcommandsRepeatable
public boolean subcommandsRepeatable()Returns whether the subcommands of this command are repeatable, that is, whether such subcommands can occur multiple times and may be followed by sibling commands instead of just child commands.- Since:
- 4.2
- See Also:
-
toString
Returns a string representation of this command, used in error messages and trace messages. -
name
Sets the String to use as the program name in the synopsis line of the help message.- Returns:
- this CommandSpec for method chaining
-
aliases
Sets the alternative names by which this subcommand is recognized on the command line.- Returns:
- this CommandSpec for method chaining
- Since:
- 3.1
-
defaultValueProvider
Returns the default value provider for this command.- Returns:
- the default value provider or
null - Since:
- 3.6
-
defaultValueProvider
public CommandLine.Model.CommandSpec defaultValueProvider(CommandLine.IDefaultValueProvider defaultValueProvider) Sets default value provider for this command.- Parameters:
defaultValueProvider- the default value provider to use, ornull.- Returns:
- this CommandSpec for method chaining
- Since:
- 3.6
-
version
Sets version information literals for this command, to print to the console when the user specifies an option to request version help. Only used if noversionProvideris set.- Returns:
- this CommandSpec for method chaining
-
versionProvider
Sets version provider for this command, to generate theversion()strings.- Parameters:
versionProvider- the version provider to use to generate the version strings, ornullif the version literals should be used.- Returns:
- this CommandSpec for method chaining
-
helpCommand
Sets whether this is a help command and required parameter checking should be suspended.- Returns:
- this CommandSpec for method chaining
- See Also:
-
exitCodeOnSuccess
Sets exit code for successful termination. 0 by default.- Since:
- 4.0
- See Also:
-
exitCodeOnUsageHelp
Sets exit code for successful termination after printing usage help on user request. 0 by default.- Since:
- 4.0
- See Also:
-
exitCodeOnVersionHelp
Sets exit code for successful termination after printing version help on user request. 0 by default.- Since:
- 4.0
- See Also:
-
exitCodeOnInvalidInput
Sets exit code for command line usage error. 2 by default.- Since:
- 4.0
- See Also:
-
exitCodeOnExecutionException
Sets exit code signifying that an exception occurred when invoking the Runnable, Callable or Method user object of a command. 1 by default.- Since:
- 4.0
- See Also:
-
inherited
public boolean inherited()Returns whether this command is inherited from a parent command.- Since:
- 4.6
- See Also:
-
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).- Returns:
- whether this argument applies to all descendent subcommands of the command where it is defined
- Since:
- 4.6
-
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.6
-
modelTransformer
Returns the model transformer for this CommandSpec instance.- Since:
- 4.6
-
modelTransformer
public CommandLine.Model.CommandSpec modelTransformer(CommandLine.IModelTransformer modelTransformer) Sets the model transformer for this CommandSpec instance.- Since:
- 4.6
-
preprocessor
Returns the preprocessor for this CommandSpec instance.- Since:
- 4.6
-
preprocessor
Sets the preprocessor for this CommandSpec instance.- Since:
- 4.6
-
negatableOptionTransformer
public CommandLine.Model.CommandSpec negatableOptionTransformer(CommandLine.INegatableOptionTransformer newValue) Sets theINegatableOptionTransformerused to create the negative form of negatable options. Note thatoptionsCaseInsensitive()will also change the case sensitivity of negatable options: any customCommandLine.INegatableOptionTransformerthat was previously installed will be replaced by the case-insensitive version of the default transformer. To ensure your custom transformer is used, install it last, after changing case sensitivity.- Since:
- 4.0
- See Also:
-
mixinStandardHelpOptions
Sets whether the standard help options should be mixed in with this command.- Returns:
- this CommandSpec for method chaining
- See Also:
-
subcommandsRepeatable
Sets whether the subcommands of this command are repeatable, that is, whether such subcommands can occur multiple times and may be followed by sibling commands instead of just child commands.- Since:
- 4.2
- See Also:
-
withToString
Sets the string representation of this command, used in error messages and trace messages.- Parameters:
newValue- the string representation- Returns:
- this CommandSpec for method chaining
-
updateCommandAttributes
Updates the following attributes from the specified@Commandannotation: aliases,parser separator, command name, version, help command, version provider, default provider andusage message spec.- Parameters:
cmd- the@Commandannotation to get attribute values fromfactory- factory used to instantiate classes- Since:
- 3.7
-
initAliases
-
initName
-
initHelpCommand
void initHelpCommand(boolean value) -
initVersion
-
initVersionProvider
-
initDefaultValueProvider
-
initDefaultValueProvider
void initDefaultValueProvider(Class<? extends CommandLine.IDefaultValueProvider> value, CommandLine.IFactory factory) -
initSubcommandsRepeatable
void initSubcommandsRepeatable(boolean value) -
initExitCodeOnSuccess
void initExitCodeOnSuccess(int exitCode) -
initExitCodeOnUsageHelp
void initExitCodeOnUsageHelp(int exitCode) -
initExitCodeOnVersionHelp
void initExitCodeOnVersionHelp(int exitCode) -
initExitCodeOnInvalidInput
void initExitCodeOnInvalidInput(int exitCode) -
initExitCodeOnExecutionException
void initExitCodeOnExecutionException(int exitCode) -
updateName
-
initModelTransformer
-
updateModelTransformer
void updateModelTransformer(Class<? extends CommandLine.IModelTransformer> value, CommandLine.IFactory factory) -
initPreprocessor
-
updatePreprocessor
void updatePreprocessor(Class<? extends CommandLine.IParameterPreprocessor> value, CommandLine.IFactory factory) -
updateHelpCommand
void updateHelpCommand(boolean value) -
updateSubcommandsRepeatable
void updateSubcommandsRepeatable(boolean value) -
updateAddMethodSubcommands
void updateAddMethodSubcommands(boolean value) -
updateVersion
-
updateVersionProvider
void updateVersionProvider(Class<? extends CommandLine.IVersionProvider> value, CommandLine.IFactory factory) -
updateExitCodeOnSuccess
void updateExitCodeOnSuccess(int exitCode) -
updateExitCodeOnUsageHelp
void updateExitCodeOnUsageHelp(int exitCode) -
updateExitCodeOnVersionHelp
void updateExitCodeOnVersionHelp(int exitCode) -
updateExitCodeOnInvalidInput
void updateExitCodeOnInvalidInput(int exitCode) -
updateExitCodeOnExecutionException
void updateExitCodeOnExecutionException(int exitCode) -
updateScopeType
-
findOption
Returns the option with the specified short name, ornullif no option with that name is defined for this command. -
findOption
Returns the option with the specified name, ornullif no option with that name is defined for this command.- Parameters:
name- used to search the options. May include option name prefix characters or not.
-
findOption
static CommandLine.Model.OptionSpec findOption(char shortName, Iterable<CommandLine.Model.OptionSpec> options) -
findOption
static CommandLine.Model.OptionSpec findOption(String name, List<CommandLine.Model.OptionSpec> options) -
stripPrefix
-
findVisibleOptionNamesWithPrefix
-
resemblesOption
-