Package nz.org.riskscape.picocli
Class CommandLine.AbstractParseResultHandler<R>
java.lang.Object
nz.org.riskscape.picocli.CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>>
nz.org.riskscape.picocli.CommandLine.AbstractParseResultHandler<R>
- All Implemented Interfaces:
CommandLine.IExecutionStrategy
,CommandLine.IParseResultHandler2<R>
- Direct Known Subclasses:
CommandLine.RunAll
,CommandLine.RunFirst
,CommandLine.RunLast
- Enclosing class:
- CommandLine
@Deprecated
public abstract static class CommandLine.AbstractParseResultHandler<R>
extends CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>>
implements CommandLine.IParseResultHandler2<R>, CommandLine.IExecutionStrategy
Deprecated.
Command line parse result handler that returns a value. This handler prints help if requested, and otherwise calls
handle(CommandLine.ParseResult)
with the parse result. Facilitates implementation of the CommandLine.IParseResultHandler2
interface.
Note that AbstractParseResultHandler
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 AbstractParseResultHandler<MyReturnType> {
protected MyReturnType handle(ParseResult parseResult) throws ExecutionException { ... }
protected MyResultHandler self() { return this; }
}
- Since:
- 3.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
execute
(CommandLine.ParseResult parseResult) Deprecated."Executes" the user input and returns an exit code.protected List<CommandLine.IExitCodeGenerator>
extractExitCodeGenerators
(CommandLine.ParseResult parseResult) Deprecated.protected abstract R
handle
(CommandLine.ParseResult parseResult) Deprecated.Processes the specifiedParseResult
and returns the result as a list of objects.handleParseResult
(CommandLine.ParseResult parseResult) Deprecated.Prints help if requested, and otherwise callshandle(CommandLine.ParseResult)
.Methods inherited from class nz.org.riskscape.picocli.CommandLine.AbstractHandler
andExit, ansi, colorScheme, err, exit, exitCode, hasExitCode, out, returnResultOrExit, self, throwOrExit, useAnsi, useErr, useOut
-
Constructor Details
-
AbstractParseResultHandler
public AbstractParseResultHandler()Deprecated.
-
-
Method Details
-
handleParseResult
public R handleParseResult(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException Deprecated.Prints help if requested, and otherwise callshandle(CommandLine.ParseResult)
. Finally, either a list of result objects is returned, or the JVM is terminated if an exit code was set.- Specified by:
handleParseResult
in interfaceCommandLine.IParseResultHandler2<R>
- Parameters:
parseResult
- theParseResult
that resulted from successfully parsing the command line arguments- Returns:
- the result of
processing parse results
- Throws:
CommandLine.ParameterException
- if theHelpCommand
was invoked for an unknown subcommand. AnyParameterExceptions
thrown from this method are treated as if this exception was thrown during parsing and passed to theCommandLine.IExceptionHandler2
CommandLine.ExecutionException
- if a problem occurred while processing the parse results; client code can useCommandLine.ExecutionException.getCommandLine()
to get the command or subcommand where processing failed
-
execute
Deprecated.Description copied from interface:CommandLine.IExecutionStrategy
"Executes" the user input and returns an exit code. Execution often means invoking a method on the selected CommandSpec's user object, and making the return value of that invocation available via
setExecutionResult
.- Specified by:
execute
in interfaceCommandLine.IExecutionStrategy
- Parameters:
parseResult
- the parse result from which to select one or moreCommandSpec
instances to execute.- Returns:
- an exit code
- Throws:
CommandLine.ExecutionException
- if any problem occurred while executing the command. Any exceptions (other than ParameterException) should be wrapped in a ExecutionException and not thrown as is.
-
handle
protected abstract R handle(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException Deprecated.Processes the specifiedParseResult
and returns the result as a list of objects. Implementations are responsible for catching any exceptions thrown in thehandle
method, and rethrowing anExecutionException
that details the problem and captures the offendingCommandLine
object.- Parameters:
parseResult
- theParseResult
that resulted from successfully parsing the command line arguments- Returns:
- the result of processing parse results
- Throws:
CommandLine.ExecutionException
- if a problem occurred while processing the parse results; client code can useCommandLine.ExecutionException.getCommandLine()
to get the command or subcommand where processing failed
-
extractExitCodeGenerators
protected List<CommandLine.IExitCodeGenerator> extractExitCodeGenerators(CommandLine.ParseResult parseResult) Deprecated.
-
CommandLine.execute(String...)
,CommandLine.getExecutionStrategy()
,CommandLine.getParameterExceptionHandler()
,CommandLine.getExecutionExceptionHandler()