Package io.dropwizard.core.cli
Class Command
java.lang.Object
io.dropwizard.core.cli.Command
- Direct Known Subclasses:
ConfiguredCommand
A basic CLI command.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
configure
(net.sourceforge.argparse4j.inf.Subparser subparser) Configure the command'sSubparser
.final String
Returns the command's description.final String
getName()
Returns the command's name.void
Method is called if there is an issue parsing configuration, setting up the environment, or running the command itself.abstract void
Executes when the user runs this specific command.
-
Constructor Details
-
Command
Create a new command with the given name and description.- Parameters:
name
- the name of the command, used for command line invocationdescription
- a description of the command's purpose
-
-
Method Details
-
getName
Returns the command's name.- Returns:
- the command's name
-
getDescription
Returns the command's description.- Returns:
- the command's description
-
configure
public abstract void configure(net.sourceforge.argparse4j.inf.Subparser subparser) Configure the command'sSubparser
.- Parameters:
subparser
- theSubparser
specific to the command
-
run
public abstract void run(Bootstrap<?> bootstrap, net.sourceforge.argparse4j.inf.Namespace namespace) throws Exception Executes when the user runs this specific command.- Parameters:
bootstrap
- the bootstrapnamespace
- the parsed command line namespace- Throws:
Exception
- if something goes wrong
-
onError
Method is called if there is an issue parsing configuration, setting up the environment, or running the command itself. The default is printing the stacktrace to facilitate debugging, but can be customized per command.- Parameters:
cli
- contains the streams for stdout and stderrnamespace
- the parsed arguments from the commandlinee
- The exception that was thrown when setting up or running the command
-