Class Command

java.lang.Object
io.dropwizard.core.cli.Command
Direct Known Subclasses:
ConfiguredCommand

public abstract class Command extends Object
A basic CLI command.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Command(String name, String description)
    Create a new command with the given name and description.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    configure(net.sourceforge.argparse4j.inf.Subparser subparser)
    Configure the command's Subparser.
    final String
    Returns the command's description.
    final String
    Returns the command's name.
    void
    onError(Cli cli, net.sourceforge.argparse4j.inf.Namespace namespace, Throwable e)
    Method is called if there is an issue parsing configuration, setting up the environment, or running the command itself.
    abstract void
    run(Bootstrap<?> bootstrap, net.sourceforge.argparse4j.inf.Namespace namespace)
    Executes when the user runs this specific command.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Command

      protected Command(String name, String description)
      Create a new command with the given name and description.
      Parameters:
      name - the name of the command, used for command line invocation
      description - a description of the command's purpose
  • Method Details

    • getName

      public final String getName()
      Returns the command's name.
      Returns:
      the command's name
    • getDescription

      public final String 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's Subparser.
      Parameters:
      subparser - the Subparser 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 bootstrap
      namespace - the parsed command line namespace
      Throws:
      Exception - if something goes wrong
    • onError

      public void onError(Cli cli, net.sourceforge.argparse4j.inf.Namespace namespace, Throwable e)
      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 stderr
      namespace - the parsed arguments from the commandline
      e - The exception that was thrown when setting up or running the command