Interface ICommand
- All Known Implementing Classes:
AbstractParentCommand
,AbstractTerminalCommand
public interface ICommand
A command line interface command.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Collection<? extends org.apache.commons.cli.Option>
Used to gather options directly associated with this command.Get a description of what the command does.default List<ExtraArgument>
Get the non-option arguments.getName()
Get the name of the command.default ICommand
getSubCommandByName
(String name) Get a sub-command by it's command name.default Collection<ICommand>
Get any sub-commands associated with this command.default boolean
Determine if this command requires the use of a sub-command.newExecutor
(CLIProcessor.CallingContext callingContext, org.apache.commons.cli.CommandLine commandLine) Create a new executor for this command.default void
validateExtraArguments
(CLIProcessor.CallingContext callingContext, org.apache.commons.cli.CommandLine commandLine) Validates that the provided extra arguments meet expectations.default void
validateOptions
(CLIProcessor.CallingContext callingContext, org.apache.commons.cli.CommandLine commandLine) Validate the options provided on the command line based on what is required for this command.
-
Method Details
-
getName
Get the name of the command.This name is used to call the command as a command line argument.
- Returns:
- the command's name
-
getDescription
Get a description of what the command does.This description is displayed in help output.
- Returns:
- the description
-
getExtraArguments
Get the non-option arguments.- Returns:
- the arguments, or an empty list if there are no arguments
-
gatherOptions
Used to gather options directly associated with this command.- Returns:
- the options
-
getSubCommands
Get any sub-commands associated with this command.- Returns:
- the sub-commands
-
getSubCommandByName
Get a sub-command by it's command name.- Parameters:
name
- the requested sub-command name- Returns:
- the command or
null
if no sub-command exists with that name
-
isSubCommandRequired
Determine if this command requires the use of a sub-command.- Returns:
true
if a sub-command is required orfalse
otherwise
-
validateOptions
default void validateOptions(@NonNull CLIProcessor.CallingContext callingContext, @NonNull org.apache.commons.cli.CommandLine commandLine) throws InvalidArgumentException Validate the options provided on the command line based on what is required for this command.- Parameters:
callingContext
- the context of the command executioncommandLine
- the parsed command line details- Throws:
InvalidArgumentException
- if a problem was found while validating the options
-
newExecutor
@NonNull ICommandExecutor newExecutor(@NonNull CLIProcessor.CallingContext callingContext, @NonNull org.apache.commons.cli.CommandLine commandLine) Create a new executor for this command.- Parameters:
callingContext
- the context of the command executioncommandLine
- the parsed command line details- Returns:
- the executor
-
validateExtraArguments
default void validateExtraArguments(@NonNull CLIProcessor.CallingContext callingContext, @NonNull org.apache.commons.cli.CommandLine commandLine) throws InvalidArgumentException Validates that the provided extra arguments meet expectations.- Parameters:
callingContext
- the context of the command executioncommandLine
- the parsed command line details- Throws:
InvalidArgumentException
- if a problem was found while validating the extra arguments
-