From 867d414548a736eb1002c0049e27100d635a8b0f Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Thu, 20 Apr 2017 22:16:25 +0200 Subject: [PATCH] Initialize help flag in initHelpCmd Fix #302 --- command.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index f4705f9..79956f3 100644 --- a/command.go +++ b/command.go @@ -721,7 +721,13 @@ func (c *Command) ExecuteC() (cmd *Command, err error) { func (c *Command) initHelpFlag() { c.mergePersistentFlags() if c.Flags().Lookup("help") == nil { - c.Flags().BoolP("help", "h", false, "help for "+c.Name()) + usage := "help for " + if c.Name() == "" { + usage += "this command" + } else { + usage += c.Name() + } + c.Flags().BoolP("help", "h", false, usage) } } @@ -745,6 +751,7 @@ func (c *Command) initHelpCmd() { c.Printf("Unknown help topic %#q\n", args) c.Root().Usage() } else { + cmd.initHelpFlag() // make possible 'help' flag to be shown cmd.Help() } },