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

docs: added documentations and help message for setup completions when used as kubectl plugin #793

Merged
merged 2 commits into from
Dec 25, 2023
Merged

Conversation

nekomeowww
Copy link
Contributor

@nekomeowww nekomeowww commented Oct 25, 2023

Close #786.

Summary

  • Added a new hack script to proxy arguments to Cobra's _completion command
  • Translated documentation for Simplified Chinese
  • Refined the original documentations for English
  • Refined the help message of completion sub command, for better reading experience and instructions
  • Added instructions about how to configure and setup the completions for kubectl kc

Demo

completion --help now prints:

❯ ./main completion --help
To load completions for kubecm cli:

For Bash users:

  # To load completions for the current session, execute once:
  source <(kubecm completion bash)

  # To load completions for each session, execute once (you will need to start a new
  # shell for this setup to take effect.):

  # Linux:
  kubecm completion bash > /etc/bash_completion.d/kubecm

  # macOS:
  kubecm completion bash > /usr/local/etc/bash_completion.d/kubecm

For Zsh users, execute:

  # If shell completion is not already enabled in your environment,
  # you will need to enable it.  You can execute the following once:

  echo "autoload -U compinit; compinit" >> ~/.zshrc

  # To load completions for each session, execute once (you will need to start a new
  # shell for this setup to take effect.):
  kubecm completion zsh > "${fpath[1]}/_kubecm"

For fish users, execute:

  # Load completions for the current session, execute once:
  kubecm completion fish | source

  # Load completions for each session, execute once (you will need to start a new
  # shell for this setup to take effect.):
  kubecm completion fish > ~/.config/fish/completions/kubecm.fish

For PowerShell users, execute:

  # To load completions for the current session, execute once:
  kubecm completion powershell | Out-String | Invoke-Expression

  # To load completions for every new session, run:
  kubecm completion powershell > kubecm.ps1
  # and source this file from your PowerShell profile.

---

To load completions for kubectl kc when used as kubectl plugin:

1. Use the following command as one-liner to add the completion to the current shell session:

  mkdir -p ~/.config/.kubectl-plugin-completions
  cat <<EOF >~/.config/.kubectl-plugin-completions/kubectl_complete-kc
  #!/usr/bin/env sh

  # Call the __complete command passing it all arguments
  kubectl kc __complete "\$@"
  EOF
  chmod +x ~/.config/.kubectl-plugin-completions/kubectl_complete-kc

2. Append the directory to the $PATH environment variable.

For Bash users, execute:

  echo 'export PATH=$PATH:~/.config/.kubectl-plugin-completions' >> ~/.bashrc

For Zsh users, execute:

  echo 'export PATH=$PATH:~/.config/.kubectl-plugin-completions' >> ~/.zshrc

For fish users, execute:

  fish_add_path ~/.config/.kubectl-plugin-completions

---

Usage:
  kubecm completion [bash|zsh|fish|powershell] [flags]

Aliases:
  completion, c

Flags:
  -h, --help   help for completion

Global Flags:
      --config string   path of kubeconfig (default "/Users/neko/.kube/config")
  -m, --mac-notify      enable to display Mac notification banner
      --ui-size int     number of list items to show in menu at once (default 4)

And kubectl kc now works:

asciicast

Test & Verifications

  • bash
  • zsh
  • fish
  • PowerShell (on macOS)

@the-label-bot the-label-bot bot added the kind/feature ategorizes issue or PR as related to a new feature. label Oct 25, 2023
@the-label-bot
Copy link

the-label-bot bot commented Oct 25, 2023

The Label Bot has predicted the following:

Category Value Confidence Applied Label
Kind feature 0.911 ✔️
Size L 0.980 ✔️

@the-label-bot the-label-bot bot added the size/L size/L label Oct 25, 2023
Copy link
Owner

@sunny0826 sunny0826 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 LGTM, Thanks for your contribute !

@sunny0826
Copy link
Owner

Sorry the Review is a little late, I've just recently taken a little time out.

@sunny0826 sunny0826 merged commit 54f96af into sunny0826:master Dec 25, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature ategorizes issue or PR as related to a new feature. size/L size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Cannot complete commands with kubectl kc
2 participants