Package org.elasticsearch.cli
Class Command
java.lang.Object
org.elasticsearch.cli.Command
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
MultiCommand
public abstract class Command
extends java.lang.Object
implements java.io.Closeable
An action to execute within a cli.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringdescriptionA description of the command, used in the help output.protected joptsimple.OptionParserparserThe option parser for this command. -
Constructor Summary
Constructors Constructor Description Command(java.lang.String description, java.lang.Runnable beforeMain)Construct the command with the specified command description and runnable to execute before main is invoked. -
Method Summary
Modifier and Type Method Description protected booleanaddShutdownHook()Return whether or not to install the shutdown hook to cleanup resources on exit.voidclose()protected abstract voidexecute(Terminal terminal, joptsimple.OptionSet options)Executes this command.protected static voidexit(int status)intmain(java.lang.String[] args, Terminal terminal)Parses options for this command from args and executes it.protected voidprintAdditionalHelp(Terminal terminal)Prints additional help information, specific to the command
-
Field Details
-
description
protected final java.lang.String descriptionA description of the command, used in the help output. -
parser
protected final joptsimple.OptionParser parserThe option parser for this command.
-
-
Constructor Details
-
Command
public Command(java.lang.String description, java.lang.Runnable beforeMain)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:
java.lang.Exception
-
printAdditionalHelp
Prints additional help information, specific to the command -
exit
protected static void exit(int status) -
execute
protected abstract void execute(Terminal terminal, joptsimple.OptionSet options) throws java.lang.ExceptionExecutes this command. Any runtime user errors (like an input file that does not exist), should throw aUserException.- Throws:
java.lang.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
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-