-
Notifications
You must be signed in to change notification settings - Fork 433
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
Disable required checks from subcommand #268
Comments
Very good point! This is also useful for the auto-help feature included in picocli 3.0-alpha-1 (in master, not released yet). Quick recap: at the moment there are two places where required parameters are checked:
In both cases, the required params check is omitted if a help option was previously encountered. One idea is to add a new attribute to Now that I'm thinking about it, perhaps the Thoughts? |
Would it cause any problems to remove 1), and allow the check in 2) to be disabled ? |
Can you explain more details about your use case? I want to understand the problem better before jumping into possible solutions. Why does your subcommand need to disable validation of required parameters in its parent command? |
basically I have a subcommand with many subcommands all of the subcommands of the subcommand require a username and password, which I've added to the parent subcommand. However one of those sub-sub-commands doesn't require username and password, so I would have preferred to be able to just disable the required check on the parent, rather than having to move username and password into every child subcommand (so the use case does has a workaround, but i thought it would be nicer to have that flexibility in picocli) |
That sounds like the model doesn't quite fit. Should the parent subcommand really require a username and password if not all its subcommands need it? An alternative way to model this would be to create a username/password mixin that is only added to the subcommands that actually need it. |
Yet another alternative is to do the validation in your app instead of letting picocli do it. To accomplish this, make username and password non-required options of the parent command. Add a method to the parent command that performs the validation (prints the "missing required parameter..." message and usage help if username or password is missing). Call this method only from the subcommands that actually require the username and password. |
I could move it to the subcommand using mixin or subclassing, in my specific use case it's workaroundable... i was just thinking having that flexibility could be useful for other uses cases as well (an help subcommand like you mentioned would be another one) |
I am not 100% happy with the current implementation for AutoHelp. I would like users to be able to create custom help commands. At least two things are missing for that to work:
I'm glad to have this discussion with you since it is not easy to spot what is missing when trying to think things through by yourself. Appreciated! |
Commands can now be annotated with This is now in master. |
I wanted to have the ability to have a subcommand which will disable validation of required parameters in a parent subcommand.
I started working on it by following the same model as isHelpRequested().
However unless I'm completely missing something it doesn't seem like that's going to work since help doesn't seem to disable required in parent subcommands :(
So it kinda looks like this would end up requiring major architectural changes so that the required checks are done at the end after all parsing is completed, is that correct ?
The text was updated successfully, but these errors were encountered: