Skip to content
Myr

Add tests about additional help topics

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

authored by Eric Paris · committed by Eric Paris · parent f576d29 · 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
69 unmodified lines
70 rootcalled = true71 },72}7374var cmdSubNoRun = &Command{75 Use: "subnorun",76 Short: "A subcommand without a Run function",77 Long: "A long output about a subcommand without a Run function",78}7980var cmdVersion1 = &Command{81 Use: "version",82 Short: "Print the version number",83 Long: `First version of the version command`,
17 unmodified lines
101 cmdTimes.ResetFlags()102 cmdRootNoRun.ResetFlags()103 cmdRootSameName.ResetFlags()104 cmdRootWithRun.ResetFlags()105 cmdSubNoRun.ResetFlags()106 cmdRootNoRun.PersistentFlags().StringVarP(&flags2a, "strtwo", "t", "two", strtwoParentHelp)107 cmdEcho.Flags().IntVarP(&flagi1, "intone", "i", 123, "help message for flag intone")108 cmdTimes.Flags().IntVarP(&flagi2, "inttwo", "j", 234, "help message for flag inttwo")109 cmdPrint.Flags().IntVarP(&flagi3, "intthree", "i", 345, "help message for flag intthree")
14 unmodified lines
124 cmdTimes.ResetCommands()125 cmdRootNoRun.ResetCommands()126 cmdRootSameName.ResetCommands()127 cmdRootWithRun.ResetCommands()128 cmdSubNoRun.ResetCommands()129}130131func initialize() *Command {132 tt, tp, te = nil, nil, nil
61 unmodified lines
194 buf := new(bytes.Buffer)195 // Testing flag with invalid input196 c.SetOutput(buf)197 cmdEcho.AddCommand(cmdTimes)190 c.AddCommand(cmdPrint, cmdEcho)198 c.AddCommand(cmdPrint, cmdEcho, cmdSubNoRun)199 c.SetArgs(strings.Split(input, " "))200201 err := c.Execute()202 output := buf.String()
292 unmodified lines
495 }496}497498func TestHelpCommand(t *testing.T) {491 c := fullSetupTest("help echo")492 checkResultContains(t, c, cmdEcho.Long)499 x := fullSetupTest("help")500 checkResultContains(t, x, cmdRootWithRun.Long)501502 x = fullSetupTest("help echo")503 checkResultContains(t, x, cmdEcho.Long)504494 r := fullSetupTest("help echo times")495 checkResultContains(t, r, cmdTimes.Long)505 x = fullSetupTest("help echo times")506 checkResultContains(t, x, cmdTimes.Long)507}508509func TestChildCommandHelp(t *testing.T) {510 c := noRRSetupTest("print --help")
1 unmodified line
512 r := noRRSetupTest("echo times --help")513 checkResultContains(t, r, strtwoChildHelp)514}515516func TestNonRunChildHelp(t *testing.T) {517 x := noRRSetupTest("subnorun")518 checkResultContains(t, x, cmdSubNoRun.Long)519}520521func TestRunnableRootCommand(t *testing.T) {522 fullSetupTest("")523524 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