When using svcat, it would be helpful to have similar autocompletion capabilities as kubectl.
svcat completion should output shell completion content similar to kubectl completion. Looks interesting! I might take a look. Full disclosure: I'm very new to k8s and came here from your tweet.
Is this expected for bash completion only or should this work with PowerShell as well.
@orthros I'm glad you decided to help out! 馃挅 The expectation is bash completion similar to what kubectl completion generates, which I believe is actually something that our cli framework spf13/cobra does for us if we only hooked it up.
The last bullet point in this issue doesn't come for free with cobra, and should probably be a separate issue so don't worry about it.
So to be clear, powershell support is not expected as part of this issue. 馃榾
NEAT!
I've been looking at other systems, and how they use cobra to generate their bash completion.
I've noticed in some projects (like rkt and etcd) they have a cobra command to generate the bash completion and call that command to generate their files during build.
For example: in rkt, their rkt/rkt.mk file has a build-completions task which calls
$(RKT_BINARY) completion bash > dist/bash_completion/rtk.bash.
Would we want something similar added to the build pipeline here?
I suggest that we stick with the UX for kubectl:
$ kubectl completion --help
Output shell completion code for the specified shell (bash or zsh). The shell code must be evaluated to provide
interactive completion of kubectl commands. This can be done by sourcing it from the .bash _profile.
Detailed instructions on how to do this are available here:
https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
Examples:
# Installing bash completion on macOS using homebrew
## If running Bash 3.2 included with macOS
brew install bash-completion
## or, if running Bash 4.1+
brew install bash-completion@2
## If kubectl is installed via homebrew, this should start working immediately.
## If you've installed via other means, you may need add the completion to your completion directory
kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl
# Installing bash completion on Linux
## Load the kubectl completion code for bash into the current shell
source <(kubectl completion bash)
## Write bash completion code to a file and source if from .bash_profile
kubectl completion bash > ~/.kube/completion.bash.inc
printf "
# Kubectl shell completion
source '$HOME/.kube/completion.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile
# Load the kubectl completion code for zsh[1] into the current shell
source <(kubectl completion zsh)
# Set the kubectl completion code for zsh[1] to autoload on startup
kubectl completion zsh > "${fpath[1]}/_kubectl"
Usage:
kubectl completion SHELL [options]
Since we don't distribute via homebrew, I don't see a need to generate the files during the build?
I have a working version of this now. The code and UX is based off of kubeadm and kubectl as suggested.
An example
$ svcat
bind deprovision get provision touch
completion describe install sync unbind
$ svcat get
bindings brokers classes instances plans
$ svcat get b
bindings brokers
$ svcat get brokers
This is wirtten so it can be expanded to support other shells like zsh and fish (like kubectl does).
Right now I'm working on adding test cases and hope to have a PR shortly.