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.CloseableAn 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
-
-
-
Constructor Detail
-
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 Detail
-
main
public final int main(java.lang.String[] args, Terminal terminal) throws java.lang.ExceptionParses options for this command from args and executes it.- Throws:
java.lang.Exception
-
printAdditionalHelp
protected void printAdditionalHelp(Terminal terminal)
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.Exception
Executes 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
-
-