Repository navigation
v2: fix(completion): --flag=val breaks zsh completion - #5680
Conversation
This is a bug I ran into when working on Helm completion. I was surprised that it didn't happen when I was using kubectl, so I investigated and found a PR that fixed this bug in kubectl: kubernetes/kubernetes#48553 I duplicated the code in this commit which: Removes __helm_declare, which is safe to do since `declare -F` is already replaced to `whence -w` by __helm_convert_bash_to_zsh(). The problem was that calling "declare" from inside a function scopes the declaration to that function only. So "declare" should not be called through __helm_declare() but instead directly. To reproduce: 1- setup helm completion in zsh 2- helm --kubeconfig=$HOME/.kube/config statu<TAB> you will get the error: __helm_handle_flag:27: bad math expression: operand expected at end of string Co-authored-by: Kazuki Suda <[email protected]> Signed-off-by: Marc Khouzam <[email protected]>
PR helm#5072 followed by helm#5406 tweaked the handling of the associative array 'aliashash' when in zsh. However, upon further investigation the root of the problem was the 'aliashash' was not being declared properly as it was declared within a method and therefore not accessible to the rest of the completion script. The previous commit of this PR makes the necessary change to properly declare 'aliashash' which makes the previous tweak unecessary. This commit removes the tweak. Signed-off-by: Marc Khouzam <[email protected]>
eddiezane
left a comment
There was a problem hiding this comment.
LGTM. Should be the actual fix. Same thing I did in digitalocean/doctl#403 albeit I didn't quite understand it at the time.
This reverts commit d2ab3f5. The reverted commit turned out to be a workaroud another problem. The real fix is submitted in PR helm#5680 Signed-off-by: Marc Khouzam <[email protected]>
Turns out that removing the quotes from the associate array 'aliashash' is still required, but because it is needed for completion of alias commands. For example helm dep <TAB> does not complete as expected (as if it was 'helm dependency') if the quotes are not removed. This is because although bash ignores quotes when using associative arrays, zsh does not. So when looking for an alias aliashash[dep] will not match the entry aliashash["dep"] in zsh but will for bash. Therefore, removing the quotes fixes things. Signed-off-by: Marc Khouzam <[email protected]>
|
@eddiezane you may be interested in applying a similar commit as 48f0e31 for doctl if you use command aliases. |
|
/retest |
|
@marckhouzam Try doing a forced push to do a rebuild. |
Signed-off-by: Marc Khouzam <[email protected]>
b11ceda to
08650b2
Compare
This reverts commit d2ab3f5. The reverted commit turned out to be a workaroud another problem. The real fix is submitted in PR helm#5680 Signed-off-by: Marc Khouzam <[email protected]>
|
I run on this problem, would this fix be merged ? |
Signed-off-by: Marc Khouzam <[email protected]>
ab54e82 to
eb838bf
Compare
|
The https://github.com/helm/acceptance-testing repo can help maintainers get a feel that this change is safe. If you run the completion tests on the master branch now they will pass. (I know this PASS -> FAIL after a PR is merged is not ideal, but with the tests being in a different repo, it is difficult to handle corresponding PRs). For helm v2, to run the completion tests you can do the following. And then look at the logs in |
|
@mattfarina As discussed, this PR is important to eventually get v2 auto-complete to play well with v3 auto-complete during the migration period. |
What this PR does / why we need it:
zsh completion cannot handle the flag format --flag=val.
Special notes for your reviewer:
This is a bug I ran into when working on Helm completion.
I was surprised that it didn't happen when I was using
kubectl, so I investigated and found a PR that fixed this
bug in kubectl:
kubernetes/kubernetes#48553
I've marked the original author, @superbrothers , as a co-author to this PR.
I duplicated the code in this commit which:
Removes __helm_declare, which is safe to do since
declare -Fis already replaced towhence -wby__helm_convert_bash_to_zsh().
The problem was that calling "declare" from inside a function
scopes the declaration to that function only. So "declare"
should not be called through __helm_declare() but instead
directly.
To reproduce:
1- setup helm completion in zsh
2- helm --kubeconfig=$HOME/.kube/config statu<TAB>
you will get the error:
__helm_handle_flag:27: bad math expression: operand expected at end of string
Co-authored-by: Kazuki Suda [email protected]
Signed-off-by: Marc Khouzam [email protected]
I realized that this bug was also the root of the problem of #5046. With this PR
fixing the issue in the proper way, I've added a commit to remove
the previous fix for #5046 (PR #5072 and #5406).
However, for completely other reasons, we still need to remove the quotes from the aliashash associative array in zsh. I've therefore put it back.