Class Command

java.lang.Object
org.elasticsearch.cli.Command
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
MultiCommand

public abstract class Command extends Object implements Closeable
An action to execute within a cli.
  • Field Details

    • description

      protected final String description
      A description of the command, used in the help output.
    • parser

      protected final joptsimple.OptionParser parser
      The option parser for this command.
  • Constructor Details

    • Command

      public Command(String description)
      Construct the command with the specified command description and runnable to execute before main is invoked.
      Parameters:
      description - the command description
  • Method Details

    • main

      public final int main(String[] args, Terminal terminal, ProcessInfo processInfo) throws Exception
      Parses options for this command from args and executes it.
      Throws:
      Exception
    • mainWithoutErrorHandling

      protected void mainWithoutErrorHandling(String[] args, Terminal terminal, ProcessInfo processInfo) throws Exception
      Executes the command, but all errors are thrown.
      Throws:
      Exception
    • parseOptions

      public joptsimple.OptionSet parseOptions(String[] args)
      Parse command line arguments for this command.
      Parameters:
      args - The string arguments passed to the command
      Returns:
      A set of parsed options
    • printAdditionalHelp

      protected void printAdditionalHelp(Terminal terminal)
      Prints additional help information, specific to the command
    • printUserException

      protected void printUserException(Terminal terminal, UserException e)
    • exit

      protected static void exit(int status)
    • execute

      protected abstract void execute(Terminal terminal, joptsimple.OptionSet options, ProcessInfo processInfo) throws Exception
      Executes this command. Any runtime user errors (like an input file that does not exist), should throw a UserException.
      Throws:
      Exception
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException