Package nz.org.riskscape.picocli
Class CommandLine.RunFirst
java.lang.Object
nz.org.riskscape.picocli.CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>>
nz.org.riskscape.picocli.CommandLine.AbstractParseResultHandler<List<Object>>
nz.org.riskscape.picocli.CommandLine.RunFirst
- All Implemented Interfaces:
CommandLine.IExecutionStrategy,CommandLine.IParseResultHandler,CommandLine.IParseResultHandler2<List<Object>>
- Enclosing class:
- CommandLine
public static class CommandLine.RunFirst
extends CommandLine.AbstractParseResultHandler<List<Object>>
implements CommandLine.IParseResultHandler
Command line execution strategy that prints help if requested, and otherwise executes the top-level
Runnable or Callable command.
For use by the execute method.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected List<CommandLine.IExitCodeGenerator>extractExitCodeGenerators(CommandLine.ParseResult parseResult) handle(CommandLine.ParseResult parseResult) Executes the top-levelRunnableorCallablesubcommand.handleParseResult(List<CommandLine> parsedCommands, PrintStream out, CommandLine.Help.Ansi ansi) Prints help if requested, and otherwise executes the top-levelRunnableorCallablecommand.protected CommandLine.RunFirstself()Returnsthisto allow method chaining when calling the setters for a fluent API.Methods inherited from class nz.org.riskscape.picocli.CommandLine.AbstractParseResultHandler
execute, handleParseResultMethods inherited from class nz.org.riskscape.picocli.CommandLine.AbstractHandler
andExit, ansi, colorScheme, err, exit, exitCode, hasExitCode, out, returnResultOrExit, throwOrExit, useAnsi, useErr, useOut
-
Constructor Details
-
RunFirst
public RunFirst()
-
-
Method Details
-
handleParseResult
public List<Object> handleParseResult(List<CommandLine> parsedCommands, PrintStream out, CommandLine.Help.Ansi ansi) Prints help if requested, and otherwise executes the top-levelRunnableorCallablecommand. 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 eitherRunnableorCallable, anExecutionExceptionis thrown detailing the problem and capturing the offendingCommandLineobject.- Specified by:
handleParseResultin interfaceCommandLine.IParseResultHandler- Parameters:
parsedCommands- theCommandLineobjects that resulted from successfully parsing the command line argumentsout- thePrintStreamto print help to if requestedansi- 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 anullelement if the top-level command was aRunnable - 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.IExceptionHandlerCommandLine.ExecutionException- if a problem occurred while processing the parse results; useCommandLine.ExecutionException.getCommandLine()to get the command or subcommand where processing failed
-
handle
protected List<Object> handle(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException Executes the top-levelRunnableorCallablesubcommand. If the top-level command does not implement eitherRunnableorCallableand is not aMethod, anExecutionExceptionis thrown detailing the problem and capturing the offendingCommandLineobject.- Specified by:
handlein classCommandLine.AbstractParseResultHandler<List<Object>>- Parameters:
parseResult- theParseResultthat 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 anullelement if the last (sub)command was aRunnable - Throws:
CommandLine.ExecutionException- if a problem occurred while processing the parse results; useCommandLine.ExecutionException.getCommandLine()to get the command or subcommand where processing failed- Since:
- 3.0
-
extractExitCodeGenerators
protected List<CommandLine.IExitCodeGenerator> extractExitCodeGenerators(CommandLine.ParseResult parseResult) - Overrides:
extractExitCodeGeneratorsin classCommandLine.AbstractParseResultHandler<List<Object>>
-
self
Description copied from class:CommandLine.AbstractHandlerReturnsthisto allow method chaining when calling the setters for a fluent API.- Specified by:
selfin classCommandLine.AbstractHandler<List<Object>,CommandLine.AbstractParseResultHandler<List<Object>>>
-