Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expected behavior of getExecutionResult() with RunAll stategy ? #2127

Open
sbernard31 opened this issue Sep 28, 2023 · 2 comments
Open

expected behavior of getExecutionResult() with RunAll stategy ? #2127

sbernard31 opened this issue Sep 28, 2023 · 2 comments

Comments

@sbernard31
Copy link
Contributor

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.

@remkop
Copy link
Owner

remkop commented Sep 28, 2023

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.

@sbernard31
Copy link
Contributor Author

(Thx on my side this issue can be closed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants