Package org.elasticsearch.cli
Class Command
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 TypeMethodDescriptionprotected booleanReturn whether or not to install the shutdown hook to cleanup resources on exit.voidclose()protected abstract voidExecutes this command.protected static voidexit(int status) final intParses options for this command from args and executes it.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 descriptionbeforeMain- the before-main runnable
-
-
Method Details
-
main
Parses options for this command from args and executes it.- Throws:
Exception
-
printAdditionalHelp
Prints additional help information, specific to the command -
printUserException
-
exit
protected static void exit(int status) -
execute
Executes this command. Any runtime user errors (like an input file that does not exist), should throw aUserException.- Throws:
Exception
-
addShutdownHook
protected boolean addShutdownHook()Return whether or not to install the shutdown hook to cleanup resources on exit. This method should only be overridden in test classes.- Returns:
- whether or not to install the shutdown hook
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-