Skip to content

Support fish completion - #8111

Closed
kri5 wants to merge 2 commits into
helm:masterfrom
kri5:master
Closed

kri5 wants to merge 2 commits into
helm:masterfrom
kri5:master

Conversation

@kri5

@kri5 kri5 commented May 13, 2020

Copy link
Copy Markdown

What this PR does / why we need it:

This PR delegates support for completion entirely to cobra.

This allows to support more shells without the need to maintain specific code on helm side.

closes #8109

@helm-bot helm-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 13, 2020
@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 13, 2020
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 13, 2020
@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 13, 2020
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 13, 2020
@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 13, 2020
@helm-bot helm-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 13, 2020
@kri5

kri5 commented May 13, 2020

Copy link
Copy Markdown
Author

Sorry for the noise on this PR.

I first tried to change the name of the binary directly when the command is created, but it leads to tests not passing because the name is also used for usage, and tests hardcode "helm" binary name.

So i went for a method were i override "just-in-time" the name of the command, in order to generate completion with cobra only and get rid of any "completion" code specific to a shell in helm.

Then i added the support for the shells cobra already supports.

Feel free to comment

@marckhouzam marckhouzam left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really excited about this contribution! It is great to see others getting involved with Helm completion code.

Note that for the Fish completion code to also work with Cobra 1.0, we need PR #7906 to get merged.

Comment thread cmd/helm/completion.go Outdated
}
__helm_compopt() {
true # don't do anything. Not supported by bashcompinit in zsh
return cmd.GenZshCompletion(out)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cobra 1.0's support for Zsh is a lesser solution than what helm currently provides.
The biggest issue is that it does not support custom completions, so
helm status <TAB> would no longer work, for example.

We first need spf13/cobra#1070 to be merged and released before we can start using Cobra's Zsh completion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Comment thread cmd/helm/completion.go Resolved
Comment thread cmd/helm/completion.go Resolved
Comment thread cmd/helm/completion.go Outdated
// both helm2 and helm3), we overwrite the new binary name to the command
// in order to generate proper completion
rootCmd := cmd.Root()
rootCmd.Use = filepath.Base(os.Args[0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned about unknown side-effects of doing this.
But it may be ok. I'm just leaving a note to keep thinking about it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to create a deep copy of the command?
I haven't investigated much as if the command was still used afterwards.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler than a deep-copy could be to

  • set Use field
  • generate completion script
  • reset Use field to old value.

But all this feels hacky to me.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems hacky to me too, but i think that's a job for cobra, it definitly should be configurable.
Meanwhile we might want something like that.

I changed the way it was done in order to save/restore the Use field in fe31b1d

@marckhouzam

Copy link
Copy Markdown
Member

I just remembered that as it stands, custom completions (helm status <TAB>) will not work for Fish. We have to move all our custom completion code to Cobra 1.0.0.

I have a patch ready for that but it first needs #7906 to get merged.

@marckhouzam

Copy link
Copy Markdown
Member

I just remembered that as it stands, custom completions (helm status <TAB>) will not work for Fish. We have to move all our custom completion code to Cobra 1.0.0.

I have a patch ready for that but it first needs #7906 to get merged.

#7906 was merged 🎉 and I have posted the follow-up PR #8131 which is required to allow Fish completions to have custom completions.

@marckhouzam

Copy link
Copy Markdown
Member

@kri5, if you want to rework this PR to only focus on Fish completion (no changes to Bash or Zsh), we could bring it in right away, even before #8131. That would at least provide fish completion for commands and flags.

@marckhouzam

Copy link
Copy Markdown
Member

Hi @kri5 . PR #8131 which moved all dynamic completions to Cobra's new framework has been merged. This means we can get full Fish completion support very easily.

Will you have time to adapt your PR to limit it to Fish completion? If not, I can take it over if it helps. Thanks.

@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 12, 2020
@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 12, 2020
@helm-bot helm-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 12, 2020
@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 12, 2020
@kri5

kri5 commented Jun 12, 2020

Copy link
Copy Markdown
Author

Sorry for the late response, there should be only fish completion related changes.
Feel free to comment :)

Comment thread cmd/helm/completion.go Resolved
@marckhouzam marckhouzam changed the title Delegate shell completions to cobra for all shells Support fish completion Jun 15, 2020

@marckhouzam marckhouzam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there.

Comment thread cmd/helm/completion.go Outdated
}

func runCompletionFish(out io.Writer, cmd *cobra.Command) error {
return cmd.GenFishCompletion(out, !completionNoDesc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this does not work. You need to call cmd.Root().GenFishCompletion(...).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a fix for this, this might have been a leftover of previous commits, where cmd was overwritten by cmd.Root()

Comment thread cmd/helm/completion.go Resolved
kri5 added 2 commits June 16, 2020 17:36
Signed-off-by: Christophe Courtaut <[email protected]>
This allow to choose if descriptions in completions
are generated for shells supporting it.

Signed-off-by: Christophe Courtaut <[email protected]>
@marckhouzam marckhouzam added this to the 3.4.0 milestone Jun 18, 2020
@marckhouzam

marckhouzam commented Jun 18, 2020 •

Copy link
Copy Markdown
Member

Because we're waiting for #8314 let's target the 3.4 release for this improvement.

@marckhouzam

marckhouzam commented Jul 7, 2020 •

Copy link
Copy Markdown
Member

@kri5 could you rebase this PR to adapt to #8314 which has just been merged? You will then be able to add the --no-descriptions flag to the fish command only.

@marckhouzam

Copy link
Copy Markdown
Member

Hi @kri5. Just checking to see if you will have some time to work on the fish completion rebase. There's no real urgency since it's targeted for the 3.4 release but I just wanted to ask. Thanks.

@marckhouzam

Copy link
Copy Markdown
Member

Hi @kri5. With 3.3 released, work has begun for helm 3.4. Will you be able to rebase this PR so we can provide fish completion?

If you are unable to, I can take it over if you prefer?

@marckhouzam

Copy link
Copy Markdown
Member

I have pushed a new PR, #8664, to replace this one, to make sure it makes it on time for the 3.4 release, with some soak time.

Thank you @kri5 for getting the ball rolling on this change. Any future contribution is welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Completion for shells supported by cobra

3 participants