-
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
Persistent*Run of rootCmd will be skipped if its sub-command has the same Persistent*Run #1198
Comments
What you can do is have the |
@marckhouzam Oh, thanks! I found this logic, so why did you authors make this decision? Lines 863 to 873 in 9ed1d71
Btw, as per your answer, I tried this code snippet in the sub-cmd, and got stack overflow: PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if parentPreE := cmd.Parent().PersistentPreRunE; parentPreE != nil {
if err := parentPreE(cmd, args); err != nil {
return err
}
}
// blab ... blab ... blah
return nil
}, It works after I changed |
I can't say for sure what the original intent was, but based on our current discussion, this approach seems to give the most flexibility. It allows to either override an ancestor's
I'm guessing the problem is that you pass |
@marckhouzam Thanks for your help! I think we can close this issue now. |
@hyorigo would you mind closing the issue yourself? I don't have permissions. |
OK. Done. |
I spent some time with https://github.com/carolynvs/stingoftheviper , and I found the strange behavior ---
If I need the Persistent*Run of rootCmd and its sub-command both being triggered, what should I do? Or maybe the current behavior is a bug?
The text was updated successfully, but these errors were encountered: