mirror of
https://github.com/spf13/cobra
synced 2025-05-05 04:47:22 +00:00
Handle errors in built-in help command
This commit is contained in:
parent
ed27f317d7
commit
89ff61a542
1 changed files with 7 additions and 6 deletions
13
command.go
13
command.go
|
@ -1115,15 +1115,16 @@ Simply type ` + c.Name() + ` help [path to command] for full details.`,
|
|||
}
|
||||
return completions, ShellCompDirectiveNoFileComp
|
||||
},
|
||||
Run: func(c *Command, args []string) {
|
||||
RunE: func(c *Command, args []string) error {
|
||||
cmd, _, e := c.Root().Find(args)
|
||||
if cmd == nil || e != nil {
|
||||
if e != nil {
|
||||
return e
|
||||
} else if cmd == nil {
|
||||
c.PrintErrf("Unknown help topic %#q\n", args)
|
||||
CheckErr(c.Root().Usage())
|
||||
} else {
|
||||
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
|
||||
CheckErr(cmd.Help())
|
||||
return c.Root().Usage()
|
||||
}
|
||||
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
|
||||
return cmd.Help()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue