Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Add zsh completion to svcat #2023

Merged
merged 20 commits into from
May 18, 2018

Conversation

kikisdeliveryservice
Copy link
Contributor

@kikisdeliveryservice kikisdeliveryservice commented May 8, 2018

closes: #1912

This is my first PR for svcat.

Issue 1912 requires two steps to close:

  • 1. bump spf13/cobra to 0.0.1 (or above)
  • 2. add zsh completion - zsh completion for svcat is added

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 8, 2018
@carolynvs carolynvs self-requested a review May 8, 2018 18:58
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 8, 2018
Copy link
Contributor

@carolynvs carolynvs left a 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:

https://github.com/kubernetes-incubator/service-catalog/blob/6c3b534ef42f177f79aff53e943c1378cccae255/cmd/svcat/svcat_test.go#L151

  1. touch cmd/svcat/testdata/output/completion-zsh.txt
  2. Add a test case for zsh to that function, and have it write the output to the file you created in step 1.
  3. 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 {
Copy link
Contributor

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)

Copy link
Contributor

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%. 👍

Copy link
Contributor

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

Copy link
Contributor

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.

@kikisdeliveryservice
Copy link
Contributor Author

kikisdeliveryservice commented May 15, 2018

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.

Copy link
Contributor

@carolynvs carolynvs left a 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?

  1. svcat v<TAB> completes to svcat version
  2. svcat get b<TAB> completes to svcat get bindings.

@kikisdeliveryservice
Copy link
Contributor Author

@carolynvs

  1. yes!
  2. svcat get b actually has two options: bindings and brokers. so can confirm:
    svcat get b --> shows on next line: bindings brokers
    svcat get bi --> svcat get bindings
    svcat get br --> svcat get brokers

@carolynvs carolynvs changed the title WIP : Add zsh completion to svcat Add zsh completion to svcat May 16, 2018
Copy link
Contributor

@carolynvs carolynvs left a 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! 👍

@teaguecole
Copy link
Contributor

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)

@kikisdeliveryservice
Copy link
Contributor Author

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.

@arschles
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

@n3wscott n3wscott added the LGTM2 label May 18, 2018
@carolynvs carolynvs merged commit 2fd20f3 into kubernetes-retired:master May 18, 2018
@kikisdeliveryservice kikisdeliveryservice deleted the bug1912 branch May 23, 2018 06:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. LGTM1 LGTM2 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add zsh completion to svcat
7 participants