Package picocli
Class CommandLine.RunAll
- java.lang.Object
-
- picocli.CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>>
-
- picocli.CommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>>
-
- picocli.CommandLine.RunAll
-
- All Implemented Interfaces:
CommandLine.IExecutionStrategy,CommandLine.IParseResultHandler,CommandLine.IParseResultHandler2<java.util.List<java.lang.Object>>
- Enclosing class:
- CommandLine
public static class CommandLine.RunAll extends CommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>> implements CommandLine.IParseResultHandler
Command line execution strategy that prints help if requested, and otherwise executes the top-level command and all subcommands asRunnable,CallableorMethod. For use by theexecutemethod.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description RunAll()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intexecute(CommandLine.ParseResult parseResult)"Executes" the user input and returns an exit code.protected java.util.List<CommandLine.IExitCodeGenerator>extractExitCodeGenerators(CommandLine.ParseResult parseResult)protected java.util.List<java.lang.Object>handle(CommandLine.ParseResult parseResult)Executes the top-level command and all subcommands asRunnableorCallable.java.util.List<java.lang.Object>handleParseResult(java.util.List<CommandLine> parsedCommands, java.io.PrintStream out, CommandLine.Help.Ansi ansi)Prints help if requested, and otherwise executes the top-level command and all subcommands asRunnable,CallableorMethod.protected CommandLine.RunAllself()Returnsthisto allow method chaining when calling the setters for a fluent API.-
Methods inherited from class picocli.CommandLine.AbstractParseResultHandler
handleParseResult
-
Methods inherited from class picocli.CommandLine.AbstractHandler
andExit, ansi, colorScheme, err, exit, exitCode, hasExitCode, out, returnResultOrExit, throwOrExit, useAnsi, useErr, useOut
-
-
-
-
Method Detail
-
execute
public int execute(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException
"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 viasetExecutionResult.- Specified by:
executein interfaceCommandLine.IExecutionStrategy- Overrides:
executein classCommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>>- Parameters:
parseResult- the parse result from which to select one or moreCommandSpecinstances 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.
-
handleParseResult
public java.util.List<java.lang.Object> handleParseResult(java.util.List<CommandLine> parsedCommands, java.io.PrintStream out, CommandLine.Help.Ansi ansi)
Prints help if requested, and otherwise executes the top-level command and all subcommands asRunnable,CallableorMethod. Finally, either a list of result objects is returned, or the JVM is terminated if an exit code was set. If any of theCommandLinecommands 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 the result of executing all commands:
the return values from calling the
Callablecommands,nullelements for commands that implementRunnable - 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 java.util.List<java.lang.Object> handle(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException
Executes the top-level command and all subcommands asRunnableorCallable. If any of theCommandLinecommands does not implement eitherRunnableorCallableand is not aMethod, anExecutionExceptionis thrown detailing the problem and capturing the offendingCommandLineobject.- Specified by:
handlein classCommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>>- Parameters:
parseResult- theParseResultthat resulted from successfully parsing the command line arguments- Returns:
- an empty list if help was requested, or a list containing the result of executing all commands:
the return values from calling the
Callablecommands,nullelements for commands that implementRunnable - 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 java.util.List<CommandLine.IExitCodeGenerator> extractExitCodeGenerators(CommandLine.ParseResult parseResult)
- Overrides:
extractExitCodeGeneratorsin classCommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>>
-
self
protected CommandLine.RunAll self()
Description copied from class:CommandLine.AbstractHandlerReturnsthisto allow method chaining when calling the setters for a fluent API.- Specified by:
selfin classCommandLine.AbstractHandler<java.util.List<java.lang.Object>,CommandLine.AbstractParseResultHandler<java.util.List<java.lang.Object>>>
-
-