-
Notifications
You must be signed in to change notification settings - Fork 382
Add zsh completion to svcat #2023
Add zsh completion to svcat #2023
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get cobra to do even more of the work for us. Give it a try and let me know if that works.
Then let's add a test for zsh to this test function:
touch cmd/svcat/testdata/output/completion-zsh.txt
- Add a test case for zsh to that function, and have it write the output to the file you created in step 1.
- Run the tests and tell it to update the output file from step 1 with the output.
go test ./cmd/svcat -update
.
This follows the "golden file" test pattern that you sometimes see in Go. The test's output is compared against the contents of that golden file in the output directory, and the test fails if they don't match. To make it easier to manage the golden files, we have a -update
flag for our tests that will update the golden file to match the output from the test run, instead of failing the test.
@@ -117,3 +119,154 @@ func (c *completionCmd) Run() error { | |||
func runCompletionBash(w io.Writer, cmd *cobra.Command) error { | |||
return cmd.Root().GenBashCompletion(w) | |||
} | |||
|
|||
func runCompletionZsh(out io.Writer, cmd *cobra.Command) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace this function's body with this instead?
return cmd.Root().GenZshCompletion(w)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that the workaround you have is the best way at the moment, cobra is still working on getting the zsh functionality 100%. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend moving the entire function to it's own file, like completion_cmd_zsh.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, meh... the file only doubles and it is ~250 likes. I take it back.
Hi @carolynvs background: I wasn't able to get the GenZshCompletion() working a few iterations back so I ended up implementing the kubectl / helm way (which does indeed work). As requested I have re-implemented using cobra's GenZshCompletion. It doesn't seem to be working for me still but you can pull and try it. We can always revert back to the previous change if you confirm using GenZshCompletion() is no good. |
a548181
to
e88619e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once you confirm that you've tested this out with a zsh shell and the following works?
svcat v<TAB>
completes tosvcat version
svcat get b<TAB>
completes tosvcat get bindings
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for your patience in getting this figured out and implemented! I had no idea when I created the issue that it was going to require all that extra workaround logic. Great job! 👍
This reverts commit 372d60a.
e88619e
to
e06ea1b
Compare
I just cloned her branch and it is glorious. The only thing, and I dont think it's a big deal is that you can't complete svcat help... but the svcat command with no arguments is the exact same thing so I give this my LGTM (even though I don't have those powers). TL;DR tested all the options and they work (minus help) |
Thanks for testing @teaguecole As a note, I don't believe that autocomplete for help is available for any of the shells for any of the clis that svcat zsh tracks (including svcat bash & kubectl bash/zsh), which makes sense to me given the purpose of autocomplete. |
LGTM, but I'll let folks from another org give the final LGTM label |
@@ -117,3 +119,154 @@ func (c *completionCmd) Run() error { | |||
func runCompletionBash(w io.Writer, cmd *cobra.Command) error { | |||
return cmd.Root().GenBashCompletion(w) | |||
} | |||
|
|||
func runCompletionZsh(out io.Writer, cmd *cobra.Command) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend moving the entire function to it's own file, like completion_cmd_zsh.go
@@ -117,3 +119,154 @@ func (c *completionCmd) Run() error { | |||
func runCompletionBash(w io.Writer, cmd *cobra.Command) error { | |||
return cmd.Root().GenBashCompletion(w) | |||
} | |||
|
|||
func runCompletionZsh(out io.Writer, cmd *cobra.Command) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, meh... the file only doubles and it is ~250 likes. I take it back.
closes: #1912
This is my first PR for svcat.
Issue 1912 requires two steps to close: