mirror of
https://github.com/spf13/cobra
synced 2025-05-07 13:57:21 +00:00
fix default suggestions template for multiple suggestions
This commit is contained in:
parent
eb5c65715d
commit
410e43b3fe
2 changed files with 24 additions and 5 deletions
|
@ -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 {
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Add table
Reference in a new issue