expected behavior of getExecutionResult() with RunAll stategy ?
sbernard31 opened this issue · comments
I have a main command with several nested sub commands.
I use :
CommandLine command = new CommandLine(mainCommand) .setExecutionStrategy(new RunAll());
int exitCode = command.execute(args);
Object executionResult = command.getExecutionResult(); // contain only result of the main command.
Is it the expected behavior ?
I expected to get a List<?> containing result of each executed command.
I'm able to have this behavior with :
new RunAll() {
@Override
protected java.util.List<Object> handle(picocli.CommandLine.ParseResult parseResult)
throws picocli.CommandLine.ExecutionException {
List<Object> result = super.handle(parseResult);
parseResult.commandSpec().commandLine().setExecutionResult(result);
return result;
};
}
I open this issue just in case I face a bug.
If this is the expected behavior feel free to close the issue.
This is the expected behaviour.
An alternative to your solution is to use CommandLine.getParseResult
to get a ParseResult
object.
This object allows you to query whether a subcommand was detected, and get the ParseResult
for the subcommand.
Same for sub-subcommands.
(Thx on my side this issue can be closed)