always show help if requested, even if SilenceErrors is enabled

This commit is contained in:
Sascha Holzleiter 2015-12-03 14:58:31 +01:00
parent 1c44ec8d3f
commit f6251f5f3d

View file

@ -661,13 +661,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())
} }