Class CommandResult<C extends io.dropwizard.Configuration>

  • Type Parameters:
    C - configuration type

    public class CommandResult<C extends io.dropwizard.Configuration>
    extends java.lang.Object
    Dropwizard command execution result. Note that command execution never throws exceptions: instead, all thrown exceptions are intercepted and provided as the unsuccessful execution result.

    Depending on executed command type, some object might be null (injector would be available only for environment commands).

    Output contains both out and err streams (to simulate console view, when both streams are shown in console). Error output is also collected separately for validation (all these messages are present in common output too).

    Since:
    20.11.2023
    • Constructor Summary

      Constructors 
      Constructor Description
      CommandResult​(boolean success, java.lang.Throwable exception, java.lang.String output, java.lang.String errorOutput, io.dropwizard.cli.Command command, io.dropwizard.Application<C> app, io.dropwizard.setup.Bootstrap<C> bootstrap, C configuration, io.dropwizard.setup.Environment environment, com.google.inject.Injector injector)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      io.dropwizard.Application<C> getApplication()  
      io.dropwizard.setup.Bootstrap<C> getBootstrap()  
      io.dropwizard.cli.Command getCommand()
      Could be null only if incorrect command name was specified (in this case help message would be shown by dropwizard instead of execution).
      C getConfiguration()
      Could be null for command without configuration and in case of configuration parse errors.
      io.dropwizard.setup.Environment getEnvironment()  
      java.lang.String getErrorOutput()
      Note that default command Command.onError(io.dropwizard.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
      java.lang.Throwable getException()  
      com.google.inject.Injector getInjector()
      Note: injector created only for EnvironmentCommand.
      java.lang.String getOutput()
      Note that default command Command.onError(io.dropwizard.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
      boolean isSuccess()  
      • Methods inherited from class java.lang.Object

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

      • CommandResult

        public CommandResult​(boolean success,
                             @Nullable
                             java.lang.Throwable exception,
                             java.lang.String output,
                             java.lang.String errorOutput,
                             @Nullable
                             io.dropwizard.cli.Command command,
                             io.dropwizard.Application<C> app,
                             io.dropwizard.setup.Bootstrap<C> bootstrap,
                             @Nullable
                             C configuration,
                             @Nullable
                             io.dropwizard.setup.Environment environment,
                             @Nullable
                             com.google.inject.Injector injector)
    • Method Detail

      • isSuccess

        public boolean isSuccess()
        Returns:
        true for successful execution, false is exception was thrown
      • getException

        @Nullable
        public java.lang.Throwable getException()
        Returns:
        exception, thrown during command execution (or null for successful execution)
      • getOutput

        public java.lang.String getOutput()
        Note that default command Command.onError(io.dropwizard.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
        Returns:
        console output (together with error stream to get output exactly as it would be in console) or empty string if no output
        See Also:
        for error output only
      • getErrorOutput

        public java.lang.String getErrorOutput()
        Note that default command Command.onError(io.dropwizard.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
        Returns:
        error output or empty string
      • getCommand

        @Nullable
        public io.dropwizard.cli.Command getCommand()
        Could be null only if incorrect command name was specified (in this case help message would be shown by dropwizard instead of execution). In all other cases command should not be null (it is searched manually in the bootstrap object before execution).
        Returns:
        command instance, used for execution
      • getApplication

        public io.dropwizard.Application<C> getApplication()
        Returns:
        application instance used for execution
      • getBootstrap

        public io.dropwizard.setup.Bootstrap<C> getBootstrap()
        Returns:
        bootstrap object used for execution
      • getConfiguration

        @Nullable
        public C getConfiguration()
        Could be null for command without configuration and in case of configuration parse errors.
        Returns:
        configuration instance used or null
      • getEnvironment

        @Nullable
        public io.dropwizard.setup.Environment getEnvironment()
        Returns:
        environment instance or null (for non-environment commands or startup error)
      • getInjector

        @Nullable
        public com.google.inject.Injector getInjector()
        Note: injector created only for EnvironmentCommand.
        Returns:
        injector instance or null (for non-environment commands or due to injector startup errors)