public static class CommandLine.RunFirst extends CommandLine.AbstractParseResultHandler<List<Object>> implements CommandLine.IParseResultHandler
Runnable
or Callable
command.
For use by the execute
method.Constructor and Description |
---|
RunFirst() |
Modifier and Type | Method and 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-level
Runnable or Callable subcommand. |
List<Object> |
handleParseResult(List<CommandLine> parsedCommands,
PrintStream out,
CommandLine.Help.Ansi ansi)
Prints help if requested, and otherwise executes the top-level
Runnable or Callable command. |
protected CommandLine.RunFirst |
self()
Returns
this to allow method chaining when calling the setters for a fluent API. |
handleParseResult
andExit, ansi, colorScheme, err, exit, exitCode, hasExitCode, out, returnResultOrExit, throwOrExit, useAnsi, useErr, useOut
public int execute(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException
setExecutionResult
.execute
in interface CommandLine.IExecutionStrategy
execute
in class CommandLine.AbstractParseResultHandler<List<Object>>
parseResult
- the parse result from which to select one or more CommandSpec
instances to execute.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.public List<Object> handleParseResult(List<CommandLine> parsedCommands, PrintStream out, CommandLine.Help.Ansi ansi)
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.handleParseResult
in interface CommandLine.IParseResultHandler
parsedCommands
- the CommandLine
objects that resulted from successfully parsing the command line argumentsout
- the PrintStream
to print help to if requestedansi
- for printing help messages using ANSI styles and colorsCallable
, or a null
element if the top-level command was a Runnable
CommandLine.ParameterException
- if the HelpCommand
was invoked for an unknown subcommand. Any ParameterExceptions
thrown from this method are treated as if this exception was thrown during parsing and passed to the CommandLine.IExceptionHandler
CommandLine.ExecutionException
- if a problem occurred while processing the parse results; use
CommandLine.ExecutionException.getCommandLine()
to get the command or subcommand where processing failedprotected List<Object> handle(CommandLine.ParseResult parseResult) throws CommandLine.ExecutionException
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.handle
in class CommandLine.AbstractParseResultHandler<List<Object>>
parseResult
- the ParseResult
that resulted from successfully parsing the command line argumentsCallable
, or a null
element if the last (sub)command was a Runnable
CommandLine.ExecutionException
- if a problem occurred while processing the parse results; use
CommandLine.ExecutionException.getCommandLine()
to get the command or subcommand where processing failedprotected List<CommandLine.IExitCodeGenerator> extractExitCodeGenerators(CommandLine.ParseResult parseResult)
extractExitCodeGenerators
in class CommandLine.AbstractParseResultHandler<List<Object>>
protected CommandLine.RunFirst self()
CommandLine.AbstractHandler
this
to allow method chaining when calling the setters for a fluent API.self
in class CommandLine.AbstractHandler<List<Object>,CommandLine.AbstractParseResultHandler<List<Object>>>