remkop / picocli

Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.

Home Page:https://picocli.info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)