mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
always show help if requested, even if SilenceErrors is enabled
This commit is contained in:
parent
c65e6422ff
commit
2bd8a730ae
1 changed files with 7 additions and 4 deletions
11
command.go
11
command.go
|
@ -655,13 +655,16 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
}
|
}
|
||||||
err = cmd.execute(flags)
|
err = cmd.execute(flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Always show help if requested, even if SilenceErrors is in
|
||||||
|
// effect
|
||||||
|
if err == flag.ErrHelp {
|
||||||
|
cmd.HelpFunc()(cmd, args)
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
|
||||||
// If root command has SilentErrors flagged,
|
// If root command has SilentErrors flagged,
|
||||||
// all subcommands should respect it
|
// all subcommands should respect it
|
||||||
if !cmd.SilenceErrors && !c.SilenceErrors {
|
if !cmd.SilenceErrors && !c.SilenceErrors {
|
||||||
if err == flag.ErrHelp {
|
|
||||||
cmd.HelpFunc()(cmd, args)
|
|
||||||
return cmd, nil
|
|
||||||
}
|
|
||||||
c.Println("Error:", err.Error())
|
c.Println("Error:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue