- java.lang.Object
-
- picocli.CommandLine.AbstractHandler<R,CommandLine.AbstractParseResultHandler<R>>
-
- picocli.CommandLine.AbstractParseResultHandler<List<Object>>
-
- 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-levelRunnable
orCallable
command. For use by theexecute
method.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description RunFirst()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
execute(CommandLine.ParseResult parseResult)
"Executes" the user input and returns an exit code.protected List<CommandLine.IExitCodeGenerator>
extractExitCodeGenerators(CommandLine.ParseResult parseResult)
protected List<Object>
handle(CommandLine.ParseResult parseResult)
Executes the top-levelRunnable
orCallable
subcommand.List<Object>
handleParseResult(List<CommandLine> parsedCommands, PrintStream out, CommandLine.Help.Ansi ansi)
Prints help if requested, and otherwise executes the top-levelRunnable
orCallable
command.protected CommandLine.RunFirst
self()
Returnsthis
to 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:
execute
in interfaceCommandLine.IExecutionStrategy
- Overrides:
execute
in classCommandLine.AbstractParseResultHandler<List<Object>>
- Parameters:
parseResult
- the parse result from which to select one or moreCommandSpec
instances 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 List<Object> handleParseResult(List<CommandLine> parsedCommands, PrintStream out, CommandLine.Help.Ansi ansi)
Prints help if requested, and otherwise executes the top-levelRunnable
orCallable
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 eitherRunnable
orCallable
, anExecutionException
is thrown detailing the problem and capturing the offendingCommandLine
object.- Specified by:
handleParseResult
in interfaceCommandLine.IParseResultHandler
- Parameters:
parsedCommands
- theCommandLine
objects that resulted from successfully parsing the command line argumentsout
- thePrintStream
to 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 anull
element if the top-level command was aRunnable
- Throws:
CommandLine.ParameterException
- if theHelpCommand
was invoked for an unknown subcommand. AnyParameterExceptions
thrown from this method are treated as if this exception was thrown during parsing and passed to theCommandLine.IExceptionHandler
CommandLine.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-levelRunnable
orCallable
subcommand. If the top-level command does not implement eitherRunnable
orCallable
and is not aMethod
, anExecutionException
is thrown detailing the problem and capturing the offendingCommandLine
object.- Specified by:
handle
in classCommandLine.AbstractParseResultHandler<List<Object>>
- Parameters:
parseResult
- theParseResult
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 anull
element 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:
extractExitCodeGenerators
in classCommandLine.AbstractParseResultHandler<List<Object>>
-
self
protected CommandLine.RunFirst self()
Description copied from class:CommandLine.AbstractHandler
Returnsthis
to allow method chaining when calling the setters for a fluent API.- Specified by:
self
in classCommandLine.AbstractHandler<List<Object>,CommandLine.AbstractParseResultHandler<List<Object>>>
-
-