CommandLine.AbstractHandler (picocli 3.9.6 API)
Date: 2019-04-06

picocli

## Class CommandLine.AbstractHandler<R,T extends CommandLine.AbstractHandler<R,T>>

- java.lang.Object
- - picocli.CommandLine.AbstractHandler<R,T>

- Type Parameters:
    `R` - the return type of this handler
    `T` - The type of the handler subclass; for fluent API method chaining
  Direct Known Subclasses:
    CommandLine.AbstractParseResultHandler, CommandLine.DefaultExceptionHandler
  Enclosing class:
    CommandLine

      public abstract static class CommandLine.AbstractHandler<R,T extends CommandLine.AbstractHandler<R,T>>
      extends java.lang.Object

  Abstract superclass for `CommandLine.IParseResultHandler2` and `CommandLine.IExceptionHandler2` implementations.

  Note that `AbstractHandler` is a generic type. This, along with the abstract `self` method, allows method chaining to work properly in subclasses, without the need for casts. An example subclass can look like this:

       class MyResultHandler extends AbstractHandler<MyReturnType, MyResultHandler> implements IParseResultHandler2<MyReturnType> {

           public MyReturnType handleParseResult(ParseResult parseResult) { ... }

           protected MyResultHandler self() { return this; }
       }

  Since:
    3.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractHandler()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `andExit(int exitCode)` Indicates that the handler should call `System.exit(int)` after processing completes and sets the exit code to use as the termination status.
    `CommandLine.Help.Ansi` | `ansi()` Returns the ANSI style to use.
    `java.io.PrintStream` | `err()` Returns the stream to print diagnostic messages to.
    `protected void` | `exit(int exitCode)` Calls `System.exit(int)` with the specified exit code.
    `java.lang.Integer` | `exitCode()` Returns the exit code to use as the termination status, or `null` (the default) if the handler should not call `System.exit(int)` after processing completes.
    `boolean` | `hasExitCode()` Returns `true` if an exit code was set with `andExit(int)`, or `false` (the default) if the handler should not call `System.exit(int)` after processing completes.
    `java.io.PrintStream` | `out()` Returns the stream to print command output to.
    `protected R` | `returnResultOrExit(R result)` Convenience method for subclasses that returns the specified result object if no exit code was set, or otherwise, if an exit code was set, calls `System.exit` with the configured exit code to terminate the currently running Java virtual machine.
    `protected abstract T` | `self()` Returns `this` to allow method chaining when calling the setters for a fluent API.
    `protected R` | `throwOrExit(CommandLine.ExecutionException ex)` Convenience method for subclasses that throws the specified ExecutionException if no exit code was set, or otherwise, if an exit code was set, prints the stacktrace of the specified exception to the diagnostic error stream and calls `System.exit` with the configured exit code to terminate the currently running Java virtual machine.
    `T` | `useAnsi(CommandLine.Help.Ansi ansi)` Sets the ANSI style to use.
    `T` | `useErr(java.io.PrintStream err)` Sets the stream to print diagnostic messages to.
    `T` | `useOut(java.io.PrintStream out)` Sets the stream to print command output to.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AbstractHandler

          public AbstractHandler()

  - ### Method Detail

    - #### out

          public java.io.PrintStream out()

      Returns the stream to print command output to. Defaults to `System.out`, unless `useOut(PrintStream)` was called with a different stream.

      `IParseResultHandler2` implementations should use this stream. By convention, when the user requests help with a `--help` or similar option, the usage help message is printed to the standard output stream so that it can be easily searched and paged.

    - #### err

          public java.io.PrintStream err()

      Returns the stream to print diagnostic messages to. Defaults to `System.err`, unless `useErr(PrintStream)` was called with a different stream.

      `IExceptionHandler2` implementations should use this stream to print error messages (which may include a usage help message) when an unexpected error occurs.

    - #### ansi

          public CommandLine.Help.Ansi ansi()

      Returns the ANSI style to use. Defaults to `Help.Ansi.AUTO`, unless `useAnsi(CommandLine.Help.Ansi)` was called with a different setting.

    - #### exitCode

          public java.lang.Integer exitCode()

      Returns the exit code to use as the termination status, or `null` (the default) if the handler should not call `System.exit(int)` after processing completes.
      See Also:
        `andExit(int)`

    - #### hasExitCode

          public boolean hasExitCode()

      Returns `true` if an exit code was set with `andExit(int)`, or `false` (the default) if the handler should not call `System.exit(int)` after processing completes.

    - #### returnResultOrExit

          protected R returnResultOrExit(R result)

      Convenience method for subclasses that returns the specified result object if no exit code was set, or otherwise, if an exit code was set, calls `System.exit` with the configured exit code to terminate the currently running Java virtual machine.

    - #### throwOrExit

          protected R throwOrExit(CommandLine.ExecutionException ex)

      Convenience method for subclasses that throws the specified ExecutionException if no exit code was set, or otherwise, if an exit code was set, prints the stacktrace of the specified exception to the diagnostic error stream and calls `System.exit` with the configured exit code to terminate the currently running Java virtual machine.

    - #### exit

          protected void exit(int exitCode)

      Calls `System.exit(int)` with the specified exit code.

    - #### self

          protected abstract T self()

      Returns `this` to allow method chaining when calling the setters for a fluent API.

    - #### useOut

          public T useOut(java.io.PrintStream out)

      Sets the stream to print command output to. For use by `IParseResultHandler2` implementations.
      See Also:
        `out()`

    - #### useErr

          public T useErr(java.io.PrintStream err)

      Sets the stream to print diagnostic messages to. For use by `IExceptionHandler2` implementations.
      See Also:
        `err()`

    - #### useAnsi

          public T useAnsi(CommandLine.Help.Ansi ansi)

      Sets the ANSI style to use.
      See Also:
        `ansi()`

    - #### andExit

          public T andExit(int exitCode)

      Indicates that the handler should call `System.exit(int)` after processing completes and sets the exit code to use as the termination status.