Package io.dropwizard.core.cli
Class ConfiguredCommand<T extends Configuration>
- java.lang.Object
-
- io.dropwizard.core.cli.Command
-
- io.dropwizard.core.cli.ConfiguredCommand<T>
-
- Type Parameters:
T
- theConfiguration
subclass which is loaded from the configuration file
- Direct Known Subclasses:
CheckCommand
,EnvironmentCommand
public abstract class ConfiguredCommand<T extends Configuration> extends Command
A command whose first parameter is the location of a YAML configuration file. That file is parsed into an instance of aConfiguration
subclass, which is then validated. If the configuration is valid, the command is run.- See Also:
Configuration
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConfiguredCommand(String name, String description)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected net.sourceforge.argparse4j.inf.Argument
addFileArgument(net.sourceforge.argparse4j.inf.Subparser subparser)
Adds the configuration file argument for the configured command.protected void
cleanup()
protected void
cleanupAsynchronously()
void
configure(net.sourceforge.argparse4j.inf.Subparser subparser)
Configure the command'sSubparser
.@Nullable T
getConfiguration()
Returns the parsed configuration ornull
if it hasn't been parsed yet.protected Class<T>
getConfigurationClass()
Returns theClass
of the configuration type.void
run(Bootstrap<?> wildcardBootstrap, net.sourceforge.argparse4j.inf.Namespace namespace)
Executes when the user runs this specific command.protected abstract void
run(Bootstrap<T> bootstrap, net.sourceforge.argparse4j.inf.Namespace namespace, T configuration)
Runs the command with the givenBootstrap
andConfiguration
.-
Methods inherited from class io.dropwizard.core.cli.Command
getDescription, getName, onError
-
-
-
-
Method Detail
-
getConfigurationClass
protected Class<T> getConfigurationClass()
Returns theClass
of the configuration type.- Returns:
- the
Class
of the configuration type
-
getConfiguration
public @Nullable T getConfiguration()
Returns the parsed configuration ornull
if it hasn't been parsed yet.- Returns:
- Returns the parsed configuration or
null
if it hasn't been parsed yet - Since:
- 2.0.19
-
configure
public void configure(net.sourceforge.argparse4j.inf.Subparser subparser)
Configure the command'sSubparser
.N.B.: if you override this method, you must call
super.override(subparser)
in order to preserve the configuration file parameter in the subparser.
-
addFileArgument
protected net.sourceforge.argparse4j.inf.Argument addFileArgument(net.sourceforge.argparse4j.inf.Subparser subparser)
Adds the configuration file argument for the configured command.- Parameters:
subparser
- The subparser to register the argument on- Returns:
- the register argument
-
run
public void run(Bootstrap<?> wildcardBootstrap, net.sourceforge.argparse4j.inf.Namespace namespace) throws Exception
Description copied from class:Command
Executes when the user runs this specific command.
-
cleanupAsynchronously
protected void cleanupAsynchronously()
-
cleanup
protected void cleanup()
-
run
protected abstract void run(Bootstrap<T> bootstrap, net.sourceforge.argparse4j.inf.Namespace namespace, T configuration) throws Exception
Runs the command with the givenBootstrap
andConfiguration
.- Parameters:
bootstrap
- the bootstrapnamespace
- the parsed command line namespaceconfiguration
- the configuration object- Throws:
Exception
- if something goes wrong
-
-