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
Modifier and TypeFieldDescriptionprotected final String
A description of the command, used in the help output.protected final joptsimple.OptionParser
The option parser for this command. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Return whether or not to install the shutdown hook to cleanup resources on exit.void
close()
protected abstract void
Executes this command.protected static void
exit
(int status) final int
Parses options for this command from args and executes it.protected void
printAdditionalHelp
(Terminal terminal) Prints additional help information, specific to the commandprotected void
printUserException
(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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-