-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add bash/zsh completion command #1437
Add bash/zsh completion command #1437
Conversation
Welcome @bharathi-tenneti! |
Hi @bharathi-tenneti. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
go.mod
Outdated
k8s.io/api v0.17.4 | ||
k8s.io/apimachinery v0.17.4 | ||
k8s.io/client-go v11.0.0+incompatible | ||
sigs.k8s.io/controller-runtime v0.5.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgrade the API's are not part of the scope of his PR.
Could you please revert?
@@ -10,7 +10,7 @@ spec: | |||
spec: | |||
containers: | |||
- name: kube-rbac-proxy | |||
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1 | |||
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rebase your branch with the master?
148f794
to
232c524
Compare
cmd/completion.go
Outdated
func newCompletionCmd() *cobra.Command { | ||
completionCmd := &cobra.Command{ | ||
Use: "completion", | ||
Short: "Generators for shell completions", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about we add the Lond desc and the Examples? See an example of this impl:
Line 51 in 232c524
Long: `Initialize a new project including vendor/ directory and Go package directories. |
Also, I think that the long desc could describe its purpose as to how to use it.
cmd/completion.go
Outdated
func newCompletionCmd() *cobra.Command { | ||
completionCmd := &cobra.Command{ | ||
Use: "completion", | ||
Short: "Generators for shell completions", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short: "Generators for shell completions", | |
Short: "Generators for shell completions", | |
Long:`Output shell completion code for the specified shell (bash or zsh). The shell code must be evaluated to provide interactive completion of kubebuilder commands. This can be done by sourcing it from the .bash_profile. | |
Detailed instructions on how to do this are available here: | |
<add a link for the kubebuilder docs with the further information, note that it should similar to https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion>` |
Short: "Generate bash completions", | ||
RunE: func(cmd *cobra.Command, cmdArgs []string) error { | ||
return cmd.Root().GenBashCompletion(os.Stdout) | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we need to add the Examples:
Example: `# Run the command to generate the bash completion and create the file
$kubebuilder completion bash >> ~/.kubebuilder
TODO: Add all the steps required to set up it.
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ kubebuilder completion bash >> ~/.bashrc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, | |
}, | |
Example: `To load completion run: | |
$ . <(kubebuilder completion bash) | |
To configure your bash shell to load completions for each session add to your bashrc: | |
$ echo -e "\n. <(kubebuilder completion bash)" >> ~/.bashrc | |
`, |
/ok-to-test |
@@ -0,0 +1,53 @@ | |||
# Enabling shell auto completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
`echo BASH_VERSION` | ||
|
||
#### To upgrade, you may use homebrew: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are the steps then, I do not think that we should use ### since it is for section titles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See an example of the layout applied in another place: https://deploy-preview-1437--kubebuilder.netlify.com/reference/kind.html#cheetsheet
RunE: func(cmd *cobra.Command, cmdArgs []string) error { | ||
return cmd.Root().GenZshCompletion(os.Stdout) | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt about add the examples here in the commands?
docs/book/src/quick-start.md
Outdated
</aside> | ||
|
||
<aside class="note"> | ||
<h1>Enable shell auto completion</h1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<h1>Enable shell auto completion</h1> | |
<h1>Enabling shell autocompletion</h1> |
To keep the same standard applied in the docs.
docs/book/src/quick-start.md
Outdated
<aside class="note"> | ||
<h1>Enable shell auto completion</h1> | ||
|
||
Optional: To enable kubebuilder shell auto completion, please refer to [this](./reference/completion.md) document. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: To enable kubebuilder shell auto completion, please refer to [this](./reference/completion.md) document. | |
Kubebuilder provides autocompletion support for Bash and Zsh via the command `kubebuilder completion <bash|zsh>`, which can save you a lot of typing. For further information see the [completion](./reference/completion.md) document. |
@@ -0,0 +1,29 @@ | |||
# Enable shell auto completion | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Kubebuilder completion script for Bash can be generated with the command `kubebuilder completion bash` as the Kubebuilder completion script for Zsh can be generated with the command `kubebuilder completion zsh`. | |
Note that sourcing the completion script in your shell enables Kubebuilder autocompletion. |
@@ -0,0 +1,29 @@ | |||
# Enable shell auto completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Enable shell auto completion | |
# Enabling shell autocompletion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the docs standard/format for titles
@@ -0,0 +1,29 @@ | |||
# Enable shell auto completion | |||
|
|||
## Prerequisites |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Prerequisites | |
</aside> | |
<aside class="note"> | |
<h1>Prerequisites for Bash</h1> | |
The completion Bash script depends on [bash-completion](https://github.com/scop/bash-completion), which means that you have to install this software first (you can test if you have bash-completion already installed. Also, ensure that your Bash version is 4.1+. | |
</aside> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to talk about zsh too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estroz Is the bash-completion a prerequisite for the zsh?
## Prerequisites | ||
|
||
- Bash 4.1+/zsh | ||
- bash-completion/zsh-completions v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- bash-completion/zsh-completions v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Info added in the above note.
|
||
## Prerequisites | ||
|
||
- Bash 4.1+/zsh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Bash 4.1+/zsh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Info added in the above note.
|
||
- Once installed, go ahead and add the path `/usr/local/bin/bash` in the `/etc/shells`. | ||
|
||
`sudo echo “/usr/local/bin/bash” > /etc/shells` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @bharathi-tenneti and @estroz,
- Why the sudo here is required?
- Also, note that the bash requirements is just important for the bash one and not zsh. So, we cannot have the same pre-requirements for both. See my suggestion above
- Are these steps valid for any OS? So how can we add generic steps if they are not?. I think we could do similar the structure of the kubtecl docs here. See: https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern as below #1437 (comment)
|
||
- Bash 4.1+/zsh | ||
- bash-completion/zsh-completions v2 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it should be :
Bash on Linux
//Add the steps
Bash on Mac
// Add the steps
Zsh
// Add the steps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid discussing prereq installation steps on different systems, since "linux" has various distros (read: package managers). Perhaps a link to each package would help.
Listing the prerequisite packages and versions delegates installation (which is relatively simple in this case) to the user. By doing so we also avoid doc drift in case prereqs change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estroz @camilamacedo86
As I could test out on macOS, I can list out steps for the same.
Any idea on how do folks go about for other distributions?
Can I leave a TODO note for others such as ""linux", and "zsh"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that I am not sure if the same steps will work for both (Linux or Mac).
Regards the pre-requirement for bash it is the same for kubectl and for both (Linux or Mac) its docs is addressing the same repo. There has the info over how to install in each SO.
So, IMO we can move forward with:
Enabling shell autocompletion
(introduction)
Bash
(pre-requirement note)
(steps)
Then, we can improve it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camilamacedo86
So, no changes for now. Did I understand correctly?
/approve |
ce1d5ba
to
dba820e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the preview to check the changes. Just few nits are missing here for we are able to move forward. See: https://deploy-preview-1437--kubebuilder.netlify.com/reference/completion.html
- Fix the link:
- Put the NOTE
Follow a similar protocol for zsh completion.
in an not follow its standard.
See:
``` | ||
- Restart terminal for the changes to be reflected. | ||
|
||
Follow a similar protocol for `zsh` completion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow a similar protocol for `zsh` completion. | |
</aside> | |
<aside class="note"> | |
<h1>Zsh</h1> | |
Follow a similar protocol for `zsh` completion. | |
</aside> |
/retest |
ec5adb8
to
156c9b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that a few details still with a hall to improvements, however, we can do it in a follow-up pr and it shows to attend the requirements and is OK for others as well.
So,
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bharathi-tenneti, camilamacedo86, mengqiy The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Description:
Add completion command to enable Auto bash/zsh completion.
Motivation:
To have kubebuilder cli auto completion enabled.
Closes: #1346