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

Access subcommands after parseWithHandler(new RunAll(), args)? #489

Closed
marinier opened this issue Sep 19, 2018 · 4 comments
Closed

Access subcommands after parseWithHandler(new RunAll(), args)? #489

marinier opened this issue Sep 19, 2018 · 4 comments

Comments

@marinier
Copy link
Contributor

marinier commented Sep 19, 2018

I have a command with subcommands, which are registered declaratively, and I'm interested in using this style of command line processing:

List<Object> parsed = commandLine.parseWithHandler(new RunAll(), args);

However, for unit testing purposes, I want to access the subcommand object to see if it has the correct options set, etc. Is there a way to access the subcommand object when using RunAll?

@remkop
Copy link
Owner

remkop commented Sep 20, 2018

In the unit test, if you have access to the CommandLine object, you can call CommandLine.getParseResult(). You can query this object to see which options were matched. You can also descend into the subcommands with ParseResult.hasSubcommand() and ParseResult.subcommand().

@remkop
Copy link
Owner

remkop commented Sep 20, 2018

As a side-note, it may be good to have this question on StackOverflow to build a knowledge base for other picocli users. Would you be okay with moving this conversation to StackOverflow?

@marinier
Copy link
Contributor Author

Thank you for your response; I'll post any follow ups on stackoverflow.

@remkop
Copy link
Owner

remkop commented Sep 21, 2018

I went ahead and posted this question on StackOverflow.

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

No branches or pull requests

2 participants