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 String
A description of the command, used in the help output.protected final joptsimple.OptionParser
The option parser for this command. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected abstract void
execute
(Terminal terminal, joptsimple.OptionSet options, ProcessInfo processInfo) Executes this command.protected static void
exit
(int status) final int
main
(String[] args, Terminal terminal, ProcessInfo processInfo) Parses options for this command from args and executes it.protected void
mainWithoutErrorHandling
(String[] args, Terminal terminal, ProcessInfo processInfo) Executes the command, but all errors are thrown.joptsimple.OptionSet
parseOptions
(String[] args) Parse command line arguments for this command.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 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-