R
- the return type of this handlerT
- The type of the handler subclass; for fluent API method chaining@Deprecated public abstract static class CommandLine.AbstractHandler<R,T extends CommandLine.AbstractHandler<R,T>> extends Object
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; }
}
Constructor and Description |
---|
AbstractHandler()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
T |
andExit(int exitCode)
Deprecated.
use
CommandLine.execute(String...) instead, and call System.exit() in the application. |
CommandLine.Help.Ansi |
ansi()
Deprecated.
use
colorScheme() instead |
CommandLine.Help.ColorScheme |
colorScheme()
Deprecated.
Returns the ColorScheme to use.
|
PrintStream |
err()
Deprecated.
Returns the stream to print diagnostic messages to.
|
protected void |
exit(int exitCode)
Deprecated.
Calls
System.exit(int) with the specified exit code. |
Integer |
exitCode()
Deprecated.
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()
Deprecated.
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. |
PrintStream |
out()
Deprecated.
Returns the stream to print command output to.
|
protected R |
returnResultOrExit(R result)
Deprecated.
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()
Deprecated.
Returns
this to allow method chaining when calling the setters for a fluent API. |
protected R |
throwOrExit(CommandLine.ExecutionException ex)
Deprecated.
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)
Deprecated.
|
T |
useErr(PrintStream err)
Deprecated.
use
CommandLine.setErr(PrintWriter) and CommandLine.execute(String...) instead |
T |
useOut(PrintStream out)
Deprecated.
use
CommandLine.setOut(PrintWriter) and CommandLine.execute(String...) instead |
public PrintStream out()
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.
public PrintStream err()
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.
@Deprecated public CommandLine.Help.Ansi ansi()
colorScheme()
insteadHelp.Ansi.AUTO
, unless useAnsi(CommandLine.Help.Ansi)
was called with a different setting.public CommandLine.Help.ColorScheme colorScheme()
Help#defaultColorScheme(Help.Ansi.AUTO)
.public Integer exitCode()
null
(the default) if the handler should
not call System.exit(int)
after processing completes.andExit(int)
public boolean hasExitCode()
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.protected R returnResultOrExit(R result)
System.exit
with the configured
exit code to terminate the currently running Java virtual machine.protected R throwOrExit(CommandLine.ExecutionException ex)
System.exit
with the configured
exit code to terminate the currently running Java virtual machine.protected void exit(int exitCode)
System.exit(int)
with the specified exit code.protected abstract T self()
this
to allow method chaining when calling the setters for a fluent API.@Deprecated public T useOut(PrintStream out)
CommandLine.setOut(PrintWriter)
and CommandLine.execute(String...)
instead@Deprecated public T useErr(PrintStream err)
CommandLine.setErr(PrintWriter)
and CommandLine.execute(String...)
instead@Deprecated public T useAnsi(CommandLine.Help.Ansi ansi)
CommandLine.setColorScheme(Help.ColorScheme)
and CommandLine.execute(String...)
insteadansi()
@Deprecated public T andExit(int exitCode)
CommandLine.execute(String...)
instead, and call System.exit()
in the application.System.exit(int)
after processing completes and sets the exit code to use as the termination status.