Skip to content
Myr

help displays command names instead of usage in Available Commands

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Masahiro Sano · committed by spf13 · parent 07a9dc0 · Browse files · 2 files+24 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−1 removed

  • other:+24 added−1 removed

2 files+24 added−1 removed

modified:cobra_test.go+8 added
465 unmodified lines
466 if strings.Contains(x.Output, "unknown flag: --help") {467 t.Errorf("--help shouldn't trigger an error, Got: \n %s", x.Output)468 }469470 if strings.Contains(x.Output, cmdEcho.Use) {471 t.Errorf("--help shouldn't display subcommand's usage, Got: \n %s", x.Output)472 }473474 x = fullSetupTest("echo --help")475476 if strings.Contains(x.Output, cmdTimes.Use) {477 t.Errorf("--help shouldn't display subsubcommand's usage, Got: \n %s", x.Output)478 }479480 checkResultContains(t, x, "Available Commands:")481 checkResultContains(t, x, "for more information about a command")482483 if strings.Contains(x.Output, "unknown flag: --help") {
78 unmodified lines
modified:command.go+16 added-1 removed
52 unmodified lines
53 parent *Command54 // max lengths of commands' string lengths for use in padding55 commandsMaxUseLen int56 commandsMaxCommandPathLen int57 commandsMaxNameLen int5859 flagErrorBuf *bytes.Buffer60 cmdErrorBuf *bytes.Buffer61
119 unmodified lines
181 return c.parent.commandsMaxCommandPathLen182 }183}184185var minNamePadding int = 11186187func (c *Command) NamePadding() int {188 if c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {189 return minNamePadding190 } else {191 return c.parent.commandsMaxNameLen192 }193}194195func (c *Command) UsageTemplate() string {196 if c.usageTemplate != "" {197 return c.usageTemplate198 }
9 unmodified lines
208Aliases:209 {{.NameAndAliases}}{{end}}210{{ if .HasSubCommands}}211Available Commands: {{range .Commands}}{{if .Runnable}}201 {{rpad .Use .UsagePadding }} {{.Short}}{{end}}{{end}}212 {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}213{{end}}214{{ if .HasLocalFlags}}Flags:215{{.LocalFlags.FlagUsages}}{{end}}216{{ if .HasAnyPersistentFlags}}Global Flags:
322 unmodified lines
539 commandPathLen := len(x.CommandPath())540 if commandPathLen > c.commandsMaxCommandPathLen {541 c.commandsMaxCommandPathLen = commandPathLen542 }543 nameLen := len(x.Name())544 if nameLen > c.commandsMaxNameLen {545 c.commandsMaxNameLen = nameLen546 }547 c.commands = append(c.commands, x)548 }549}550
306 unmodified lines