From 4be878bffc8eb18b30b770da0f88075a252814e1 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Mon, 23 Feb 2015 08:01:17 -0500 Subject: [PATCH] Fixing the issue with a command with subcommands not showing help message. - the command name is "" and HasName was returning true for an empty ShortName. - the Show method wasn't aware that command name was just "" and returned the first subcommand. --- command.go | 2 +- help.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 5747e52..07c919a 100644 --- a/command.go +++ b/command.go @@ -119,7 +119,7 @@ func (c Command) Run(ctx *Context) error { // Returns true if Command.Name or Command.ShortName matches given name func (c Command) HasName(name string) bool { - return c.Name == name || c.ShortName == name + return c.Name == name || (c.ShortName != "" && c.ShortName == name) } func (c Command) startApp(ctx *Context) error { diff --git a/help.go b/help.go index bfb2788..316b58d 100644 --- a/help.go +++ b/help.go @@ -112,6 +112,12 @@ func DefaultAppComplete(c *Context) { // Prints help for the given command func ShowCommandHelp(c *Context, command string) { + // show the subcommand help for a command with subcommands + if command == "" { + HelpPrinter(SubcommandHelpTemplate, c.App) + return + } + for _, c := range c.App.Commands { if c.HasName(command) { HelpPrinter(CommandHelpTemplate, c)