Package org.opensearch.cli
Class EnvironmentAwareCommand
java.lang.Object
org.opensearch.cli.Command
org.opensearch.cli.EnvironmentAwareCommand
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
KeyStoreAwareCommand
,OpenSearchNodeCommand
public abstract class EnvironmentAwareCommand
extends org.opensearch.cli.Command
A cli command which requires an
Environment
to use current paths and settings.-
Field Summary
-
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(java.util.Map<java.lang.String,java.lang.String> settings)
Create anEnvironment
for the command to use.protected Environment
createEnv(Settings baseSettings, java.util.Map<java.lang.String,java.lang.String> settings)
Create anEnvironment
for the command to use.protected void
execute(org.opensearch.cli.Terminal terminal, joptsimple.OptionSet options)
protected abstract void
execute(org.opensearch.cli.Terminal terminal, joptsimple.OptionSet options, Environment env)
Execute the command with the initializedEnvironment
.
-
Constructor Details
-
EnvironmentAwareCommand
public EnvironmentAwareCommand(java.lang.String description)Construct the command with the specified command description. This command will have logging configured without reading OpenSearch 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 Details
-
execute
protected void execute(org.opensearch.cli.Terminal terminal, joptsimple.OptionSet options) throws java.lang.Exception- Specified by:
execute
in classorg.opensearch.cli.Command
- Throws:
java.lang.Exception
-
createEnv
protected Environment createEnv(java.util.Map<java.lang.String,java.lang.String> settings) throws org.opensearch.cli.UserExceptionCreate anEnvironment
for the command to use. Overrideable for tests.- Throws:
org.opensearch.cli.UserException
-
createEnv
protected final Environment createEnv(Settings baseSettings, java.util.Map<java.lang.String,java.lang.String> settings) throws org.opensearch.cli.UserExceptionCreate anEnvironment
for the command to use. Overrideable for tests.- Throws:
org.opensearch.cli.UserException
-
execute
protected abstract void execute(org.opensearch.cli.Terminal terminal, joptsimple.OptionSet options, Environment env) throws java.lang.ExceptionExecute the command with the initializedEnvironment
.- Throws:
java.lang.Exception
-