Package picocli
Interface CommandLine.IExecutionStrategy
-
- All Known Implementing Classes:
CommandLine.AbstractParseResultHandler,CommandLine.RunAll,CommandLine.RunFirst,CommandLine.RunLast
- Enclosing class:
- CommandLine
public static interface CommandLine.IExecutionStrategyImplementations are responsible for "executing" the user input and returning an exit code. TheCommandLine.execute(String...)method delegates to a configured execution strategy.Implementation Requirements:
Implementers responsibilities are:
- From the
ParseResult, select whichCommandSpecshould be executed. This is especially important for commands that have subcommands. - "Execute" the selected
CommandSpec. Often this means invoking a method on the spec's user object. - Call
setExecutionResultto make the return value of that method invocation available to the application - Return an exit code. Common sources of exit values are the invoked method's return value, or the user object if it implements
CommandLine.IExitCodeGenerator.
Implementors that need to print messages to the console should use the output and error PrintWriters, and the color scheme from the CommandLine object obtained from ParseResult's CommandSpec.
API Note:
This interface supersedes
CommandLine.IParseResultHandler2.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intexecute(CommandLine.ParseResult parseResult)"Executes" the user input and returns an exit code.
-
-
-
Method Detail
-
execute
int execute(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException, CommandLine.ParameterException
"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.- Parameters:
parseResult- the parse result from which to select one or moreCommandSpecinstances to execute.- Returns:
- an exit code
- Throws:
CommandLine.ParameterException- if the invoked method on the CommandSpec's user object threw a ParameterException to signify invalid user input.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.
-
-