-
Notifications
You must be signed in to change notification settings - Fork 428
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
No built-in way to access parent command from subcommand? #247
Comments
You raise a good point. I’m thinking to provide an additional A reference to the parent command will be injected to any fields annotated with Would that work for you? |
Yes, that should do the job. (Incidentally, I don't think the requirements on constructors (there must be a zero-arg constructor) for commands are documented anywhere.) |
Ok. Thanks for pointing out the docs can be improved. By the way, do zero-arg constructors work for you or are you also interested in using a factory like requested in #169 ? |
Zero-arg constructors are fine for me at the moment, although it would be kind of neat to be able to use a factory. |
Pushed the new |
Reopening: still need to update the user manual. |
This issue has been addressed in picocli 2.2, which is now available on JCenter and Maven Central. |
A natural thing to do with parent commands is define options that will apply to all the subcommands. However, it's not terribly convenient to access the parent command from the subcommand: you have to rely on whatever creates the
CommandLine
to thread everything around.Similarly, the provided
IParseResultHandler
s don't make it easy to pass things around.I think what would be most convenient for me would be for a subcommand to receive an instance of its parent command as a constructor argument. That way everything is well-typed and it's easy to access the options of parent commands.
The text was updated successfully, but these errors were encountered: