mirror of
https://github.com/spf13/cobra
synced 2024-12-28 23:37:09 +00:00
fix help command: use PersistentPreRunE instead of PersistentPreRun
This commit is contained in:
parent
3bb59c6775
commit
b370e7b9af
1 changed files with 7 additions and 2 deletions
|
@ -1209,7 +1209,7 @@ Simply type ` + c.Name() + ` help [path to command] for full details.`,
|
|||
}
|
||||
return completions, ShellCompDirectiveNoFileComp
|
||||
},
|
||||
PersistentPreRun: func(cmd *Command, args []string) {
|
||||
PersistentPreRunE: func(cmd *Command, args []string) error {
|
||||
cmd.Flags().VisitAll(func(pflag *flag.Flag) {
|
||||
requiredAnnotation, found := pflag.Annotations[BashCompOneRequiredFlag]
|
||||
if found && requiredAnnotation[0] == "true" {
|
||||
|
@ -1219,7 +1219,12 @@ Simply type ` + c.Name() + ` help [path to command] for full details.`,
|
|||
})
|
||||
// Adding PersistentPreRun on sub-commands prevents root's PersistentPreRun from being called.
|
||||
// So it is intentionally called here.
|
||||
cmd.Root().PersistentPreRun(cmd.Root(), args)
|
||||
if cmd.Root().PersistentPreRunE != nil {
|
||||
return cmd.Root().PersistentPreRunE(cmd, args)
|
||||
} else if cmd.Root().PersistentPreRun != nil {
|
||||
cmd.Root().PersistentPreRun(cmd, args)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(c *Command, args []string) {
|
||||
cmd, _, e := c.Root().Find(args)
|
||||
|
|
Loading…
Reference in a new issue