Skip to content
Myr

Merge pull request #88 from eparis/subhelptest

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

Add tests about additional help topics

authored by Eric Paris · committed by Eric Paris · parents aab4e37, 86a1686 · Browse files · 2 files+23 added−6 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+23 added−6 removed

  • other:+23 added−6 removed

2 files+23 added−6 removed

modified:cobra_test.go+21 added-5 removed
70 unmodified lines
71 rootcalled = true72 },73}7475var cmdSubNoRun = &Command{76 Use: "subnorun",77 Short: "A subcommand without a Run function",78 Long: "A long output about a subcommand without a Run function",79}8081var cmdVersion1 = &Command{82 Use: "version",83 Short: "Print the version number",84 Long: `First version of the version command`,
17 unmodified lines
102 cmdTimes.ResetFlags()103 cmdRootNoRun.ResetFlags()104 cmdRootSameName.ResetFlags()105 cmdRootWithRun.ResetFlags()106 cmdSubNoRun.ResetFlags()107 cmdRootNoRun.PersistentFlags().StringVarP(&flags2a, "strtwo", "t", "two", strtwoParentHelp)108 cmdEcho.Flags().IntVarP(&flagi1, "intone", "i", 123, "help message for flag intone")109 cmdTimes.Flags().IntVarP(&flagi2, "inttwo", "j", 234, "help message for flag inttwo")110 cmdPrint.Flags().IntVarP(&flagi3, "intthree", "i", 345, "help message for flag intthree")
14 unmodified lines
125 cmdTimes.ResetCommands()126 cmdRootNoRun.ResetCommands()127 cmdRootSameName.ResetCommands()128 cmdRootWithRun.ResetCommands()129 cmdSubNoRun.ResetCommands()130}131132func initialize() *Command {133 tt, tp, te = nil, nil, nil
61 unmodified lines
195 buf := new(bytes.Buffer)196 // Testing flag with invalid input197 c.SetOutput(buf)198 cmdEcho.AddCommand(cmdTimes)191 c.AddCommand(cmdPrint, cmdEcho)199 c.AddCommand(cmdPrint, cmdEcho, cmdSubNoRun)200 c.SetArgs(strings.Split(input, " "))201202 err := c.Execute()203 output := buf.String()
303 unmodified lines
507 }508}509510func TestHelpCommand(t *testing.T) {503 c := fullSetupTest("help echo")504 checkResultContains(t, c, cmdEcho.Long)511 x := fullSetupTest("help")512 checkResultContains(t, x, cmdRootWithRun.Long)513514 x = fullSetupTest("help echo")515 checkResultContains(t, x, cmdEcho.Long)516506 r := fullSetupTest("help echo times")507 checkResultContains(t, r, cmdTimes.Long)517 x = fullSetupTest("help echo times")518 checkResultContains(t, x, cmdTimes.Long)519}520521func TestChildCommandHelp(t *testing.T) {522 c := noRRSetupTest("print --help")
1 unmodified line
524 r := noRRSetupTest("echo times --help")525 checkResultContains(t, r, strtwoChildHelp)526}527528func TestNonRunChildHelp(t *testing.T) {529 x := noRRSetupTest("subnorun")530 checkResultContains(t, x, cmdSubNoRun.Long)531}532533func TestRunnableRootCommand(t *testing.T) {534 fullSetupTest("")535536 if rootcalled != true {
243 unmodified lines
modified:command.go+2 added-1 removed
232 unmodified lines
233{{ if .HasLocalFlags}}Flags:234{{.LocalFlags.FlagUsages}}{{end}}235{{ if .HasInheritedFlags}}Global Flags:236{{.InheritedFlags.FlagUsages}}{{end}}{{if or (.HasHelpSubCommands) (.HasRunnableSiblings)}}237Additional help topics:237Additional help topics: {{if .HasHelpSubCommands}}{{range .Commands}}{{if not .Runnable}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasRunnableSiblings }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}238{{if .HasHelpSubCommands}}{{range .Commands}}{{if not .Runnable}} {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasRunnableSiblings }}{{range .Parent.Commands}}{{if .Runnable}}{{if not (eq .Name $cmd.Name) }}239 {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{end}}240{{end}}{{ if .HasSubCommands }}241Use "{{.Root.Name}} help [command]" for more information about a command.242{{end}}`
715 unmodified lines