Package io.github.qishr.cascara.common.util
Class RunFirst
java.lang.Object
io.github.qishr.cascara.common.util.CommandLine.AbstractHandler<java.util.List<java.lang.Object>
io.github.qishr.cascara.common.util.CommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>
io.github.qishr.cascara.common.util.CommandLine.RunFirst
All Implemented Interfaces:
IParseResultHandler
Enclosing Class:
io.github.qishr.cascara.common.util.CommandLine
public static class RunFirst
extends io.github.qishr.cascara.common.util.CommandLine.AbstractParseResultHandler<java.util.List<Object>
Command line IExecutionStrategy that prints help if requested, and otherwise executes the top-level
Runnable or Callable command.For use by the execute method.
Constructor Summary
| Constructor | Description |
|---|---|
| RunFirst() |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
| public int | execute(ParseResult parseResult) | |
| public List<Object> | handleParseResult(List<CommandLine> parsedCommands, PrintStream out, Ansi ansi) | Prints help if requested, and otherwise executes the top-level Runnable or Callable command. |
| protected List<Object> | handle(ParseResult parseResult) | Executes the top-level Runnable or Callable subcommand. |
| protected List<IExitCodeGenerator> | extractExitCodeGenerators(ParseResult parseResult) | |
| protected RunFirst | self() |
Method Details
execute
public int execute(ParseResult parseResult)
Throws:
handleParseResult
public List<Object> handleParseResult(List<CommandLine> parsedCommands, PrintStream out, Ansi ansi)
Prints help if requested, and otherwise executes the top-level Runnable or Callable command.Finally, either a list of result objects is returned, or the JVM is terminated if an exit code was set.
If the top-level command does not implement either Runnable or Callable, an ExecutionException
is thrown detailing the problem and capturing the offending CommandLine object.
Parameters:
parsedCommands - the CommandLine objects that resulted from successfully parsing the command line arguments
out - the PrintStream to print help to if requested
ansi - for printing help messages using ANSI styles and colors
Returns:
an empty list if help was requested, or a list containing a single element: the result of calling the
Callable, or a null element if the top-level command was a Runnable
Specified By:
handle
protected List<Object> handle(ParseResult parseResult)
Executes the top-level Runnable or Callable subcommand.If the top-level command does not implement either Runnable or Callable and is not a Method, an ExecutionException
is thrown detailing the problem and capturing the offending CommandLine object.
Parameters:
parseResult - the ParseResult that resulted from successfully parsing the command line arguments
Returns:
an empty list if help was requested, or a list containing a single element: the result of calling the
Callable, or a null element if the last (sub)command was a Runnable
Throws:
Since:
3.0
extractExitCodeGenerators
protected List<IExitCodeGenerator> extractExitCodeGenerators(ParseResult parseResult)
self
protected RunFirst self()
Overrides: