java.lang.Object
org.elasticsearch.cli.Command
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
MultiCommand
An action to execute within a cli.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringA description of the command, used in the help output.protected final joptsimple.OptionParserThe option parser for this command. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected abstract voidexecute(Terminal terminal, joptsimple.OptionSet options, ProcessInfo processInfo) Executes this command.protected static voidexit(int status) final intmain(String[] args, Terminal terminal, ProcessInfo processInfo) Parses options for this command from args and executes it.protected voidmainWithoutErrorHandling(String[] args, Terminal terminal, ProcessInfo processInfo) Executes the command, but all errors are thrown.joptsimple.OptionSetparseOptions(String[] args) Parse command line arguments for this command.protected voidprintAdditionalHelp(Terminal terminal) Prints additional help information, specific to the commandprotected voidprintUserException(Terminal terminal, UserException e)
-
Field Details
-
description
A description of the command, used in the help output. -
parser
protected final joptsimple.OptionParser parserThe option parser for this command.
-
-
Constructor Details
-
Command
Construct the command with the specified command description and runnable to execute before main is invoked.- Parameters:
description- the command description
-
-
Method Details
-
main
Parses options for this command from args and executes it.- Throws:
IOException
-
mainWithoutErrorHandling
protected void mainWithoutErrorHandling(String[] args, Terminal terminal, ProcessInfo processInfo) throws Exception Executes the command, but all errors are thrown.- Throws:
Exception
-
parseOptions
Parse command line arguments for this command.- Parameters:
args- The string arguments passed to the command- Returns:
- A set of parsed options
-
printAdditionalHelp
Prints additional help information, specific to the command -
printUserException
-
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 aUserException.- Throws:
Exception
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-