diff --git a/help_test.go b/help_test.go index 975607fd73..ae397b26b1 100644 --- a/help_test.go +++ b/help_test.go @@ -1162,21 +1162,19 @@ func TestDefaultCompleteWithFlags(t *testing.T) { for _, tc := range []struct { name string - c *Context - cmd *Command + a *App argv []string expected string }{ { name: "empty", - c: &Context{App: &App{}}, - cmd: &Command{}, + a: &App{}, argv: []string{"prog", "cmd"}, expected: "", }, - /*{ + { name: "typical-flag-suggestion", - c: &Context{App: &App{ + a: &App{ Name: "cmd", Flags: []Flag{ &BoolFlag{Name: "happiness"}, @@ -1185,66 +1183,92 @@ func TestDefaultCompleteWithFlags(t *testing.T) { Commands: []*Command{ {Name: "putz"}, }, - }}, - cmd: &Command{ - Flags: []Flag{ - &BoolFlag{Name: "excitement"}, - &StringFlag{Name: "hat-shape"}, - }, }, argv: []string{"cmd", "--e", "--generate-bash-completion"}, - expected: "--excitement\n", + expected: "--everybody-jump-on\n", }, { name: "typical-command-suggestion", - c: &Context{App: &App{ + a: &App{ Name: "cmd", Flags: []Flag{ &BoolFlag{Name: "happiness"}, &Int64Flag{Name: "everybody-jump-on"}, }, - }}, - cmd: &Command{ - Name: "putz", - Subcommands: []*Command{ - {Name: "futz"}, + Commands: []*Command{ + { + Name: "putz", + Subcommands: []*Command{ + {Name: "futz"}, + }, + Flags: []Flag{ + &BoolFlag{Name: "excitement"}, + &StringFlag{Name: "hat-shape"}, + }, + }, }, + }, + argv: []string{"cmd", "--generate-bash-completion"}, + expected: "putz\n", + }, + { + name: "typical-subcommand-suggestion", + a: &App{ + Name: "cmd", Flags: []Flag{ - &BoolFlag{Name: "excitement"}, - &StringFlag{Name: "hat-shape"}, + &BoolFlag{Name: "happiness"}, + &Int64Flag{Name: "everybody-jump-on"}, + }, + Commands: []*Command{ + { + Name: "putz", + HideHelp: true, + Subcommands: []*Command{ + {Name: "futz"}, + }, + Flags: []Flag{ + &BoolFlag{Name: "excitement"}, + &StringFlag{Name: "hat-shape"}, + }, + }, }, }, - argv: []string{"cmd", "--generate-bash-completion"}, + argv: []string{"cmd", "--happiness", "putz", "--generate-bash-completion"}, expected: "futz\n", }, { name: "autocomplete-with-spaces", - c: &Context{App: &App{ + a: &App{ Name: "cmd", Flags: []Flag{ &BoolFlag{Name: "happiness"}, &Int64Flag{Name: "everybody-jump-on"}, }, - }}, - cmd: &Command{ - Name: "putz", - Subcommands: []*Command{ - {Name: "help"}, - }, - Flags: []Flag{ - &BoolFlag{Name: "excitement"}, - &StringFlag{Name: "hat-shape"}, + Commands: []*Command{ + { + Name: "putz", + Subcommands: []*Command{ + {Name: "help"}, + }, + Flags: []Flag{ + &BoolFlag{Name: "excitement"}, + &StringFlag{Name: "hat-shape"}, + }, + }, }, }, - argv: []string{"cmd", "--url", "http://localhost:8000", "h", "--generate-bash-completion"}, + argv: []string{"cmd", "--happiness", "putz", "h", "--generate-bash-completion"}, expected: "help\n", - },*/ + }, } { t.Run(tc.name, func(ct *testing.T) { writer := &bytes.Buffer{} - tc.c.App.Writer = writer - tc.c.App.Run(tc.argv) + tc.a.EnableBashCompletion = true + tc.a.HideHelp = true + tc.a.Writer = writer + os.Args = tc.argv + tc.a.Run(tc.argv) written := writer.String()