diff --git a/app_test.go b/app_test.go index a48ca81eeb..981d074697 100644 --- a/app_test.go +++ b/app_test.go @@ -1391,46 +1391,6 @@ func TestApp_BeforeAfterFuncShellCompletion(t *testing.T) { } } -func TestApp_SubcommandShellCompletion(t *testing.T) { - - var w bytes.Buffer - - app := &App{ - Name: "command", - EnableBashCompletion: true, - Commands: []*Command{ - { - Name: "subcmd1", - Subcommands: []*Command{ - { - Name: "subcmd2", - Subcommands: []*Command{ - { - Name: "subcmd3", - }, - }, - }, - }, - }, - }, - Flags: []Flag{ - &StringFlag{Name: "opt"}, - }, - Writer: &w, - } - - // run with the Before() func succeeding - err := app.Run([]string{"command", "subcmd1", "subcmd2", "--generate-bash-completion"}) - - if err != nil { - t.Error(err) - } - - if !strings.Contains(w.String(), "subcmd3\n") { - t.Errorf("Expected subcmd3 got %s", w.String()) - } -} - func TestApp_AfterFunc(t *testing.T) { counts := &opCounts{} afterError := fmt.Errorf("fail") diff --git a/help.go b/help.go index f58ce1a6da..82d37fbb9f 100644 --- a/help.go +++ b/help.go @@ -218,8 +218,6 @@ func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context) { if cmd != nil { if cCtx.NArg() > 1 { lastArg = cCtx.Args().Get(cCtx.NArg() - 1) - } else { - lastArg = "" } } diff --git a/help_test.go b/help_test.go index ae397b26b1..736907a250 100644 --- a/help_test.go +++ b/help_test.go @@ -1221,8 +1221,7 @@ func TestDefaultCompleteWithFlags(t *testing.T) { }, Commands: []*Command{ { - Name: "putz", - HideHelp: true, + Name: "putz", Subcommands: []*Command{ {Name: "futz"}, }, @@ -1234,7 +1233,33 @@ func TestDefaultCompleteWithFlags(t *testing.T) { }, }, argv: []string{"cmd", "--happiness", "putz", "--generate-bash-completion"}, - expected: "futz\n", + expected: "futz\nhelp\nh\n", + }, + { + name: "typical-subcommand-subcommand-suggestion", + a: &App{ + Name: "cmd", + Flags: []Flag{ + &BoolFlag{Name: "happiness"}, + &Int64Flag{Name: "everybody-jump-on"}, + }, + Commands: []*Command{ + { + Name: "putz", + Subcommands: []*Command{ + { + Name: "futz", + Flags: []Flag{ + &BoolFlag{Name: "excitement"}, + &StringFlag{Name: "hat-shape"}, + }, + }, + }, + }, + }, + }, + argv: []string{"cmd", "--happiness", "putz", "futz", "-e", "--generate-bash-completion"}, + expected: "--excitement\n", }, { name: "autocomplete-with-spaces",