-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
add PersistentPreRun to disable required flag for help and completion command #1992
base: main
Are you sure you want to change the base?
add PersistentPreRun to disable required flag for help and completion command #1992
Conversation
Thanks @JunNishimura. However this change causes a couple of regressions (that are apparently not tested).
I don't think we can disable flag parsing on those commands. We have to find another approach. You may be able to add a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment
Disable any persistent required flags for the help command
disable any persistent required flags for the completion command
Thanks, @marckhouzam Your point was right. And, I appreciate the alternative suggestions. I would appreciate it if you check the commits again. |
@JunNishimura This looks pretty good. Lines 913 to 923 in dcb405a
So here is the scenario:
Because of the new I suggest that at the end of the two new Does that make sense? |
Thanks, @marckhouzam I understand the situation. I implemented to call root's PersistentPreRun in sub-command's (help and completion) PersistentPreRun. I would appreciate it if you check the commits again. |
@JunNishimura The backwards-compatibility fix is a little more complicated. For example the
To be able to propagate any error returned by Let me know if you need any clarifications, and thanks again for your efforts! |
Thanks, @marckhouzam Your point is right. I modified to use PersitentPreRunE to be able to propagate any error returned by Sorry for repeating myself, but I'd appreciate it if you'd check commits again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. Thanks @JunNishimura !
I will mark it as approved but I'll wait a little while to allow @jpmcb to have a look if he wants.
@JunNishimura The linter is failing 😢 . It is just that this PR introduce a third string Thanks |
Thanks, @marckhouzam I define a constant for "true" named |
Thanks for the quick turnaround with the linter @JunNishimura . As this change had backwards-compatibility implications
|
Planning to take a look this weekend. Thanks @marckhouzam for the heads up! |
@jpmcb If you haven't seen it because you are busy or for some reasons, that's perfectly fine, as I do not want to rush you. I would appreciate it if you could take a look when you have time. I reminded you because I thought it was possible that you simply forgot. |
This needs a rebase |
Any update? |
@marckhouzam @jpmcb I would appreciate it if you check this PR again!! |
Overview
Fixes #1918.
The auto-implemented subcommands (help and completion) did't work when MarkPersistentRequiredFlag() called on root command. So I set DisableFlagParsing true for HelpCommand and CompletionCommand (bash, zsh, fish, powershell) to avoid required flags validation.
I also added unit test to see if the code works as I expected.
Related Issue