Repository navigation
Move go custom completions to Cobra 1.0 - #8131
Conversation
69e5f6a to
e16807a
Compare
|
The force push was a rebase to master. If anyone has time to have a look, a quick way to feel warm and fuzzy about this change is to run the completion tests of the acceptance-testing repo. Which can be done from the helm repo with:
|
e16807a to
da479ff
Compare
|
Force-push done to resolve conflicts with latest master. |
| }) | ||
|
|
||
| if err != nil { | ||
| log.Fatal(err) |
There was a problem hiding this comment.
There are a number of log.Fatal calls added to the completion functions. Could this cause Helm to exit when completion is not critical? Meaning should we print an error and continue?
There was a problem hiding this comment.
I wasn't sure if it followed helm's correct practices when I added the log.Fatal() calls.
You'll notice that all of them are on the initialization code path, and not on the completion generation path. Such a log.Fatal() call would be triggered when receiving a Cobra error when setting up completion during initialization, and would be caused by a coding error. So I thought it was ok to abort helm since this would be seen immediately during development.
But I'll follow whichever best practice you recommend.
| gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
| gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= | ||
| gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= | ||
| helm.sh/helm v2.16.7+incompatible h1:3Hp8GLmr6uuBNYGmTQ4p3J4N6xKqxvFDswxHAOposlM= |
There was a problem hiding this comment.
helm-v3 should not import helm-v2
There was a problem hiding this comment.
Sorry about that. I don't know how that got there. But I should have noticed it before pushing it. I have removed it in the last push and also rebased to master.
Cobra 1.0 introduces custom Go completions. This commit replaces Helm's own solution to use Cobra's solution. This allows to completely remove Helm's internal "completion" package. Signed-off-by: Marc Khouzam <[email protected]>
da479ff to
001cb3a
Compare
|
Thanks @adamreese! |
What this PR does / why we need it:
Cobra 1.0 introduces custom Go completions. This commit replaces Helm's own solution to use Cobra's solution. This allows to completely remove Helm's internal "completion" package and reduce our maintenance burden.
It is also a requirement to benefit from other Cobra completion improvements like Fish completions (#8111), an upcoming native zsh completion, etc.
Special notes for your reviewer:
Cobra's solution is actually a port of Helm's solution so it is extremely similar. The main difference is that Cobra's solution is slightly more elegant because it introduces a new field to the Cobra command structure:
ValidArgsFunctionwhich replaces helm'scompletion.RegisterValidArgsFunc().This PR basically does the following:
internal/completion/complete.gofile (thecompletionpackage)completion.RegisterValidArgsFunc()to the newValidArgsFunctionfieldcompletion.RegisterFlagCompletionFunc()withcmd.RegisterFlagCompletionFunc()completionpackage, with the corresponding one from thecobrapackageNo functionality is changed and no new functionality is introduced.
This was mostly a
chorecommit.If applicable: