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

Shell autocomplete functions do not work correctly #2471

Closed
waddles opened this issue Jan 13, 2024 · 0 comments · Fixed by #2477
Closed

Shell autocomplete functions do not work correctly #2471

waddles opened this issue Jan 13, 2024 · 0 comments · Fixed by #2477
Labels
bug Something isn't working InProgress Marks an issue has being worked on

Comments

@waddles
Copy link

waddles commented Jan 13, 2024




Describe the bug
k9s includes shell autocompletion commands that appear to have been taken directly from kubectl except they don't work as expected.

I work with a number of contexts and switching between them, especially with OIDC, is quite slow. I prefer to start k9s with a --context flag to select my desired context upon startup but the lack of completion suggestions is frustrating.

The undocumented __complete autocomplete suggestions command only works to suggest the top level functions but does not work for suggesting options to double-dash parameters like --context.

To Reproduce

% k9s __complete ""
completion	Generate the autocompletion script for the specified shell
help	Help about any command
info	List K9s configurations info
version	Print version/build info
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

% k9s __complete - ""
:0
Completion ended with directive: ShellCompDirectiveDefault

% k9s __complete --context ""
:0
Completion ended with directive: ShellCompDirectiveDefault

Furthermore the command suggests that --completion, --help, --info, --version should also work but they end in a panic except for --help. [EDIT: - this is an incorrect statement but k9s should handle incorrect flags without panicking]

% k9s __complete -- ""
completion	Generate the autocompletion script for the specified shell
help	Help about any command
info	List K9s configurations info
version	Print version/build info
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

% k9s --version
Error: unknown flag: --version
[-snipped-]
panic: unknown flag: --version

goroutine 1 [running]:
github.com/derailed/k9s/cmd.Execute(...)
	github.com/derailed/k9s/cmd/root.go:60
main.main()
	github.com/derailed/k9s/main.go:32 +0x3c

Expected behavior
k9s should be able to suggest completion options for flags the same way kubectl does, eg.

% kubectl __complete --user ""
local
oidc
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

% k9s __complete --user ""
:0
Completion ended with directive: ShellCompDirectiveDefault

and

% kubectl __complete --context ""
microk8s
k3s
:4
Completion ended with directive: ShellCompDirectiveNoFileComp

% k9s __complete --context ""
:0
Completion ended with directive: ShellCompDirectiveDefault

Versions:

Seems to affect all versions

% k9s version
 ____  __.________
|    |/ _/   __   \______
|      < \____    /  ___/
|    |  \   /    /\___ \
|____|__ \ /____//____  >
        \/            \/

Version:    v0.31.5
Commit:     ff17fff2861c02d325fc95d536d3787b83cb3782
Date:       2024-01-12T22:03:40Z

Additional context
It took me quite a while to work out that the output from k9s completion zsh actually calls k9s __complete <flags> "string" to get its suggestions.

@derailed derailed added bug Something isn't working InProgress Marks an issue has being worked on labels Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working InProgress Marks an issue has being worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants