diff --git a/command.go b/command.go index 8596cff3..ffb1a170 100644 --- a/command.go +++ b/command.go @@ -546,8 +546,7 @@ func (c *Command) SuggestionsTemplate() string { return ` Did you mean this? -{{range .}}{{print "\t" .}}{{end}} -` +{{range .}}{{print "\t" . "\n"}}{{end}}` } func hasNoOptDefVal(name string, fs *flag.FlagSet) bool { diff --git a/command_test.go b/command_test.go index 0658dcac..cf153756 100644 --- a/command_test.go +++ b/command_test.go @@ -1205,9 +1205,8 @@ func TestSuggestions(t *testing.T) { func TestSuggestionsTemplate(t *testing.T) { rootCmd := &Command{Use: "root", Run: emptyRun} timesCmd := &Command{ - Use: "times", - SuggestFor: []string{"counts"}, - Run: emptyRun, + Use: "times", + Run: emptyRun, } rootCmd.AddCommand(timesCmd) rootCmd.SetSuggestionsTemplate(` @@ -1221,6 +1220,27 @@ customized suggestions: {{range .}}{{.}}{{end}}`) } } +func TestDefaultSuggestionsTemplateMultiLine(t *testing.T) { + rootCmd := &Command{Use: "root", Run: emptyRun} + timeCmd := &Command{ + Use: "time", + Run: emptyRun, + } + rootCmd.AddCommand(timeCmd) + timesCmd := &Command{ + Use: "times", + Run: emptyRun, + } + rootCmd.AddCommand(timesCmd) + + output, _ := executeCommand(rootCmd, "tim") + expected := "Error: unknown command \"tim\" for \"root\"\n\nDid you mean this?\n\ttime\n\ttimes\n\nRun 'root --help' for usage.\n" + + if output != expected { + t.Errorf("Unexpected response.\nExpected:\n %q\nGot:\n %q\n", expected, output) + } +} + func TestRemoveCommand(t *testing.T) { rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun} childCmd := &Command{Use: "child", Run: emptyRun}