Package io.github.qishr.cascara.common.util
Class AbstractParseResultHandler
java.lang.Object
io.github.qishr.cascara.common.util.CommandLine.AbstractHandler
io.github.qishr.cascara.common.util.CommandLine.AbstractParseResultHandler
All Implemented Interfaces:
IParseResultHandler2
Enclosing Class:
io.github.qishr.cascara.common.util.CommandLine
public static abstract class AbstractParseResultHandler
extends io.github.qishr.cascara.common.util.CommandLine.AbstractHandler
Command line parse result handler that returns a value.This handler prints help if requested, and otherwise calls handle with the parse result. Facilitates implementation of the 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
protected MyReturnType handle(ParseResult parseResult) throws ExecutionException { ... }
protected MyResultHandler self() { return this; }
} `
Constructor Summary
| Constructor | Description |
|---|---|
| AbstractParseResultHandler() |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
| public R | handleParseResult(ParseResult parseResult) | Prints help if requested, and otherwise calls handle.handle. |
| public int | execute(ParseResult parseResult) | |
| protected abstract R | handle(ParseResult parseResult) | Processes the specified ParseResult and returns the result as a list of objects. |
| protected List<IExitCodeGenerator> | extractExitCodeGenerators(ParseResult parseResult) |
Methods inherited from AbstractHandler
err, andExit, returnResultOrExit, colorScheme, ansi, useAnsi, throwOrExit, hasExitCode, self, exit, useOut, exitCode, out, useErr
Method Details
handleParseResult
public R handleParseResult(ParseResult parseResult)
Prints help if requested, and otherwise calls handle.handle.Finally, either a list of result objects is returned, or the JVM is terminated if an exit code was set.
Parameters:
parseResult - the ParseResult that resulted from successfully parsing the command line arguments
Returns:
the result of handle.handle
Throws:
Specified By:
execute
public int execute(ParseResult parseResult)
Throws:
Specified By:
handle
protected abstract R handle(ParseResult parseResult)
Processes the specified ParseResult and returns the result as a list of objects.Implementations are responsible for catching any exceptions thrown in the handle method, and
rethrowing an ExecutionException that details the problem and captures the offending CommandLine object.
Parameters:
parseResult - the ParseResult that resulted from successfully parsing the command line arguments
Returns:
the result of processing parse results
Throws:
extractExitCodeGenerators
protected List<IExitCodeGenerator> extractExitCodeGenerators(ParseResult parseResult)