All Known Implementing Classes:
AbstractParentCommand, AbstractTerminalCommand

public interface ICommand
A command line interface command.
  • Method Details

    • getName

      @NonNull String 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

      @NonNull default List<ExtraArgument> getExtraArguments()
      Get the non-option arguments.
      Returns:
      the arguments, or an empty list if there are no arguments
    • gatherOptions

      @NonNull default Collection<? extends org.apache.commons.cli.Option> gatherOptions()
      Used to gather options directly associated with this command.
      Returns:
      the options
    • getSubCommands

      @NonNull default Collection<ICommand> getSubCommands()
      Get any sub-commands associated with this command.
      Returns:
      the sub-commands
    • getSubCommandByName

      @Nullable default ICommand getSubCommandByName(@NonNull String name)
      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

      default boolean isSubCommandRequired()
      Determine if this command requires the use of a sub-command.
      Returns:
      true if a sub-command is required or false 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 execution
      commandLine - 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 execution
      commandLine - 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 execution
      commandLine - the parsed command line details
      Throws:
      InvalidArgumentException - if a problem was found while validating the extra arguments