Package picocli
Class CommandLine.AbstractParseResultHandler<R>
- java.lang.Object
-
- picocli.CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>>
-
- picocli.CommandLine.AbstractParseResultHandler<R>
-
- All Implemented Interfaces:
CommandLine.IParseResultHandler2<R>
- Direct Known Subclasses:
CommandLine.RunAll,CommandLine.RunFirst,CommandLine.RunLast
- Enclosing class:
- CommandLine
public abstract static class CommandLine.AbstractParseResultHandler<R> extends CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>> implements CommandLine.IParseResultHandler2<R>
Command line parse result handler that returns a value. This handler prints help if requested, and otherwise callshandle(CommandLine.ParseResult)with the parse result. Facilitates implementation of theCommandLine.IParseResultHandler2interface.Note that
AbstractParseResultHandleris a generic type. This, along with the abstractselfmethod, 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
Constructors Constructor Description AbstractParseResultHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Rhandle(CommandLine.ParseResult parseResult)Processes the specifiedParseResultand returns the result as a list of objects.RhandleParseResult(CommandLine.ParseResult parseResult)Prints help if requested, and otherwise callshandle(CommandLine.ParseResult).-
Methods inherited from class picocli.CommandLine.AbstractHandler
andExit, ansi, err, exit, exitCode, hasExitCode, out, returnResultOrExit, self, throwOrExit, useAnsi, useErr, useOut
-
-
-
-
Method Detail
-
handleParseResult
public R handleParseResult(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException
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:
handleParseResultin interfaceCommandLine.IParseResultHandler2<R>- Parameters:
parseResult- theParseResultthat resulted from successfully parsing the command line arguments- Returns:
- the result of
processing parse results - Throws:
CommandLine.ParameterException- if theHelpCommandwas invoked for an unknown subcommand. AnyParameterExceptionsthrown from this method are treated as if this exception was thrown during parsing and passed to theCommandLine.IExceptionHandler2CommandLine.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
-
handle
protected abstract R handle(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException
Processes the specifiedParseResultand returns the result as a list of objects. Implementations are responsible for catching any exceptions thrown in thehandlemethod, and rethrowing anExecutionExceptionthat details the problem and captures the offendingCommandLineobject.- Parameters:
parseResult- theParseResultthat 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
-
-