Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] zsh shell completion throw error #296

Closed
sunny0826 opened this issue Apr 13, 2022 · 4 comments · Fixed by #302
Closed

[bug] zsh shell completion throw error #296

sunny0826 opened this issue Apr 13, 2022 · 4 comments · Fixed by #302
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed kind/bug Something isn't working

Comments

@sunny0826
Copy link
Owner

Hi, i noticed this issue is only for fish and powershell but I have some problems with completion also on zsh.
For example on tab after kubecm I get that last option:

11:32  76% ❯ kubecm
add                                                            -- Add KubeConfig to $HOME/.kube/config
alias                                                          -- Generate alias for all contexts
clear                                                          -- Clear lapsed context, cluster and user
completion                                                     -- Generate completion script
create                                                         -- Create new KubeConfig(experiment)
delete                                                         -- Delete the specified context from the kubeconfig
help                                                           -- Help about any command
list                                                           -- List KubeConfig
merge                                                          -- Merge the KubeConfig files in the specified directory
namespace                                                      -- Switch or change namespace interactively
rename                                                         -- Rename the contexts of kubeconfig
switch                                                         -- Switch Kube Context interactively
version                                                        -- Print version info
:4                                                             Completion ended with directive: ShellCompDirectiveNoFileComp

It also happen with any other commands but the error is sometime different:

11:32  76% ❯ kubecm list
:0                                                          Completion ended with directive: ShellCompDirectiveDefault

I enabled the completion with kubecm completion zsh > "${fpath[1]}/_kubecm" and zsh version is zsh 5.8 (x86_64-ubuntu-linux-gnu), don't know if it matters but I also use oh-my-zsh.

Originally posted by @gpstuff in #76 (comment)

@sunny0826 sunny0826 added kind/bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Apr 13, 2022
@sunny0826
Copy link
Owner Author

@gpstuff thx for you feedback

@burmanm
Copy link
Contributor

burmanm commented Apr 14, 2022

This is a bug in the cobra completions, not in kubecm. I created a ticket and a PR..

spf13/cobra#1667

@marckhouzam
Copy link

The problem is probably that kubecm redirects stderr to stdout, which will break the shell completion system.
This has happened to others before 😄.
I believe this happens here:

cli.rootCmd.SetOutput(os.Stdout)

The SetOutput() function sets stderr and stdout to point to the same place. That function is deprecated in favor of the two functions SetOut() and SetErr() as you can see here: https://github.com/spf13/cobra/blob/master/command.go#L250-L268

If you really want to have stderr print to stdout, then you need to change it just for the __complete command within a PersistentPreRun

You can see some documentation about this here: https://github.com/spf13/cobra/blob/master/shell_completions.md#debugging

Making this difference between stderr and stdout for shell completion allows to print debugging information to stderr without breaking the completion scripts.

@sunny0826
Copy link
Owner Author

@marckhouzam @burmanm Thx for your feedback, this should be a historical problem and I will try to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants