-
Notifications
You must be signed in to change notification settings - Fork 424
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
Nested execution flow for subcommands is slightly awkward. #248
Comments
The You could implement a custom For example:
Usage:
|
This is a good use case though. I will be sure to mention it in the article I'm planning to write on using picocli to create command line apps with subcommands. |
Yes, you can do it, but it's a bit awkward and not very typesafe. I don't have particularly strong feelings about how you handle it, but hopefully it's a useful case to bear in mind! |
I tried to experiment with your suggestion. You can create a custom I arrive at something like this.
I think #247 is a good idea but I believe that picocli already provides the API to accomplish what you are asking for in this ticket, unless I'm missing something. |
@michaelpj Have you had a chance to think about this further? I heard your feedback that the provided mechanism is awkward and not typesafe, but I have trouble seeing how it can be improved upon. I experimented with the Please let me know if you want to propose further improvements (I'm open to ideas) or if you want to close this ticket. |
I'm on holiday at the moment and not currently thinking about this. I'll get back to you! |
I have thought about this some more. The Calling some cleanup method on the parent command after executing all commands is a perfect example of such custom processing, and it seems to me that the design caters for it well. As you point out, there is a trade-off: any custom processing needs to have some knowledge of what additional operations the commands may support, in order to invoke these operations. The alternative proposed in the original post is to push this knowledge into the commands themselves. Since #247 added support for the So, I believe all the tools are there to support the mentioned use cases. Feel free to reopen with feedback. |
Here's a fairly natural flow for a command-subcommand process:
This is kind of hard to do at the moment.
CommandLine::parseWithHandler
lets you run all the commands in sequence, and a solution to #247 would solve the problem of accessing the parent command's args and state, but the bit where the parent command also clears up its own state at the end is hard to set up.Ideally, I imagine something like:
which subcommands implement. Then there would be a natural flow where each command calls its subcommands, passing in itself.
The text was updated successfully, but these errors were encountered: