From 7b62c7df786ae4a385717290f9f5b8f2c4edc6b9 Mon Sep 17 00:00:00 2001 From: Haim Ashkenazi Date: Mon, 5 Mar 2018 00:46:00 +0200 Subject: [PATCH] zsh-completion: --version and --help still doesn't work correctly When invoking from subcommand. Modified the test to prove. --- zsh_completions_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/zsh_completions_test.go b/zsh_completions_test.go index 66b6e69..b1321c9 100644 --- a/zsh_completions_test.go +++ b/zsh_completions_test.go @@ -15,6 +15,8 @@ func TestGenZshCompletion(t *testing.T) { name string root *Command expectedExpressions []string + invocationArgs []string + skip string }{ { 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 { r := &Command{ Use: "mycmd", @@ -127,11 +129,19 @@ func TestGenZshCompletion(t *testing.T) { "--version", "--help", }, + invocationArgs: []string{ + "sub1", + }, + skip: "--version and --help are currently not generated when not running on root command", }, } for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { + if tc.skip != "" { + t.Skip(tc.skip) + } + tc.root.Root().SetArgs(tc.invocationArgs) tc.root.Execute() buf := new(bytes.Buffer) if err := tc.root.GenZshCompletion(buf); err != nil {