main
Naveen Gogineni 2 years ago
parent a9d6b0d821
commit 4a109bc0ce

@ -198,9 +198,11 @@ func (a *App) Setup() {
var newCommands []*Command var newCommands []*Command
for _, c := range a.Commands { for _, c := range a.Commands {
if c.HelpName == "" { cname := c.Name
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name) if c.HelpName != "" {
cname = c.HelpName
} }
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, cname)
c.flagCategories = newFlagCategoriesFromFlags(c.Flags) c.flagCategories = newFlagCategoriesFromFlags(c.Flags)
newCommands = append(newCommands, c) newCommands = append(newCommands, c)

@ -1914,12 +1914,12 @@ func TestApp_Run_CommandHelpName(t *testing.T) {
output := buf.String() output := buf.String()
expected := "command foo bar - does bar things" expected := "command custom bar - does bar things"
if !strings.Contains(output, expected) { if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %s", expected, output) t.Errorf("expected %q in output: %s", expected, output)
} }
expected = "command foo bar [command options] [arguments...]" expected = "command custom bar [command options] [arguments...]"
if !strings.Contains(output, expected) { if !strings.Contains(output, expected) {
t.Errorf("expected %q in output: %s", expected, output) t.Errorf("expected %q in output: %s", expected, output)
} }

@ -107,10 +107,6 @@ func (cmd *Command) Command(name string) *Command {
} }
func (c *Command) setup(ctx *Context) { func (c *Command) setup(ctx *Context) {
if c.HelpName == "" {
c.HelpName = fmt.Sprintf("%s %s", ctx.parentContext.Command.HelpName, c.Name)
}
if c.Command(helpCommand.Name) == nil && !c.HideHelp { if c.Command(helpCommand.Name) == nil && !c.HideHelp {
if !c.HideHelpCommand { if !c.HideHelpCommand {
c.Subcommands = append(c.Subcommands, helpCommand) c.Subcommands = append(c.Subcommands, helpCommand)

@ -504,13 +504,13 @@ func TestShowSubcommandHelp_CommandAliases(t *testing.T) {
func TestShowCommandHelp_Customtemplate(t *testing.T) { func TestShowCommandHelp_Customtemplate(t *testing.T) {
app := &App{ app := &App{
Name: "foo",
Commands: []*Command{ Commands: []*Command{
{ {
Name: "frobbly", Name: "frobbly",
Action: func(ctx *Context) error { Action: func(ctx *Context) error {
return nil return nil
}, },
HelpName: "foo frobbly",
CustomHelpTemplate: `NAME: CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}} {{.HelpName}} - {{.Usage}}

Loading…
Cancel
Save