Package org.elasticsearch.cli
Class EnvironmentAwareCommand
- java.lang.Object
-
- org.elasticsearch.cli.Command
-
- org.elasticsearch.cli.EnvironmentAwareCommand
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
RemoveCorruptedShardDataCommand
,UpgradeKeyStoreCommand
public abstract class EnvironmentAwareCommand extends Command
A cli command which requires anEnvironment
to use current paths and settings.
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.cli.Command
description, parser
-
-
Constructor Summary
Constructors Constructor Description EnvironmentAwareCommand(java.lang.String description)
Construct the command with the specified command description.EnvironmentAwareCommand(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 Environment
createEnv(Terminal terminal, java.util.Map<java.lang.String,java.lang.String> settings)
Create anEnvironment
for the command to use.protected void
execute(Terminal terminal, joptsimple.OptionSet options)
protected abstract void
execute(Terminal terminal, joptsimple.OptionSet options, Environment env)
Execute the command with the initializedEnvironment
.-
Methods inherited from class org.elasticsearch.cli.Command
addShutdownHook, close, exit, main, printAdditionalHelp
-
-
-
-
Constructor Detail
-
EnvironmentAwareCommand
public EnvironmentAwareCommand(java.lang.String description)
Construct the command with the specified command description. This command will have logging configured without reading Elasticsearch configuration files.- Parameters:
description
- the command description
-
EnvironmentAwareCommand
public EnvironmentAwareCommand(java.lang.String description, java.lang.Runnable beforeMain)
Construct the command with the specified command description and runnable to execute before main is invoked. Commands constructed with this constructor must take ownership of configuring logging.- Parameters:
description
- the command descriptionbeforeMain
- the before-main runnable
-
-
Method Detail
-
execute
protected void execute(Terminal terminal, joptsimple.OptionSet options) throws java.lang.Exception
-
createEnv
protected Environment createEnv(Terminal terminal, java.util.Map<java.lang.String,java.lang.String> settings) throws UserException
Create anEnvironment
for the command to use. Overrideable for tests.- Throws:
UserException
-
execute
protected abstract void execute(Terminal terminal, joptsimple.OptionSet options, Environment env) throws java.lang.Exception
Execute the command with the initializedEnvironment
.- Throws:
java.lang.Exception
-
-