From bab6d45bc6b580887b1861a5624a3bed6ce67fca Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Sun, 30 Aug 2015 12:10:14 -0400 Subject: [PATCH] Initialize the --help flag as late as possible This should let users overwrite it with something custom. Like the help sub-command. --- command.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index cbbc326..7b0e399 100644 --- a/command.go +++ b/command.go @@ -561,6 +561,9 @@ func (c *Command) Execute() (err error) { } func (c *Command) initHelp() { + if c.Flags().Lookup("help") == nil { + c.Flags().BoolVarP(&c.helpFlagVal, "help", "h", false, "help for "+c.Name()) + } if c.helpCommand == nil { if !c.HasSubCommands() { return @@ -859,7 +862,6 @@ func (c *Command) Flags() *flag.FlagSet { c.flagErrorBuf = new(bytes.Buffer) } c.flags.SetOutput(c.flagErrorBuf) - c.PersistentFlags().BoolVarP(&c.helpFlagVal, "help", "h", false, "help for "+c.Name()) } return c.flags }