mirror of https://github.com/spf13/cobra.git
zsh-completion: --version and --help still doesn't work correctly
When invoking from subcommand. Modified the test to prove.
This commit is contained in:
parent
7ce08e227e
commit
7b62c7df78
|
@ -15,6 +15,8 @@ func TestGenZshCompletion(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
root *Command
|
root *Command
|
||||||
expectedExpressions []string
|
expectedExpressions []string
|
||||||
|
invocationArgs []string
|
||||||
|
skip string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "simple command",
|
name: "simple command",
|
||||||
|
@ -112,7 +114,7 @@ func TestGenZshCompletion(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "command should run on the root command so --version and --help will be generated",
|
name: "generated flags --help and --version should be created even when not executing root cmd",
|
||||||
root: func() *Command {
|
root: func() *Command {
|
||||||
r := &Command{
|
r := &Command{
|
||||||
Use: "mycmd",
|
Use: "mycmd",
|
||||||
|
@ -127,11 +129,19 @@ func TestGenZshCompletion(t *testing.T) {
|
||||||
"--version",
|
"--version",
|
||||||
"--help",
|
"--help",
|
||||||
},
|
},
|
||||||
|
invocationArgs: []string{
|
||||||
|
"sub1",
|
||||||
|
},
|
||||||
|
skip: "--version and --help are currently not generated when not running on root command",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tcs {
|
for _, tc := range tcs {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
if tc.skip != "" {
|
||||||
|
t.Skip(tc.skip)
|
||||||
|
}
|
||||||
|
tc.root.Root().SetArgs(tc.invocationArgs)
|
||||||
tc.root.Execute()
|
tc.root.Execute()
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := tc.root.GenZshCompletion(buf); err != nil {
|
if err := tc.root.GenZshCompletion(buf); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue