Skip to content

Commit

Permalink
fix completion
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0826 committed Dec 2, 2019
1 parent 6aa672c commit b113301
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 108 deletions.
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ KubeConfig Manager
Find more information at: https://github.com/sunny0826/kubecm

Usage:
kubecm [flags]
kubecm [command]

Examples:
# List all the contexts in your kubeconfig file
kubecm


Available Commands:
add Merge configuration file with $HOME/.kube/config
completion Generates bash/zsh completion scripts
delete Delete the specified context from the kubeconfig
get Displays one or many contexts from the kubeconfig file
get Displays one or many contexts from the kubeconfig file(Will be removed in new version, move to kubecm)
help Help about any command
merge Merge the kubeconfig files in the specified directory
rename Rename the contexts of kubeconfig
switch Switch Kube Context interactively
use Sets the current-context in a kubeconfig file
switch Switch Kube Context interactively.
use Sets the current-context in a kubeconfig file(Will be removed in new version, please use kubecm swtich)
version Prints the kubecm version


Flags:
-h, --help help for kubecm

Expand Down Expand Up @@ -66,6 +72,23 @@ sudo mv kubecm /usr/local/bin/
# Add the binary in to your $PATH
```
### Auto-Completion
```bash
# bash
kubecm completion bash > ~/.kube/kubecm.bash.inc
printf "
# kubecm shell completion
source '$HOME/.kube/kubecm.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile

# add to $HOME/.zshrc
source <(kubecm completion zsh)
# or
kubecm completion zsh > "${fpath[1]}/_kubecm"
```
### Add configuration to `$HOME/.kube/config`
```bash
Expand Down Expand Up @@ -97,7 +120,7 @@ kubecm switch
```
![switch](dosc/switch.gif)
### Displays contexts
### Displays contexts(*Will be removed*)
```bash
# List all the contexts in your kubeconfig file
Expand Down Expand Up @@ -126,7 +149,7 @@ $ kubecm get
kubecm delete my-context
```
### Switch context
### Switch context(*Will be removed*)
```bash
# Use the context for the test cluster
Expand Down
27 changes: 17 additions & 10 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package cmd

import (
zsh "github.com/rsteube/cobra-zsh-gen"
"github.com/spf13/cobra"
"os"
)
Expand All @@ -24,21 +25,27 @@ import (
var completionCmd = &cobra.Command{
Use: "completion",
Short: "Generates bash/zsh completion scripts",
Long: `To load completion run
. <(bitbucket completion)
To configure your bash shell to load completions for each session add to your bashrc
# ~/.bashrc or ~/.profile
. <(bitbucket completion)
Long: `Output shell completion code for the specified shell (bash or zsh).`,
Example: `
# bash
kubecm completion bash > ~/.kube/kubecm.bash.inc
printf "
# kubecm shell completion
source '$HOME/.kube/kubecm.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile
# add to $HOME/.zshrc
source <(kubecm completion zsh)
# or
kubecm completion zsh > "${fpath[1]}/_kubecm"
`,
Run: func(cmd *cobra.Command, args []string) {
complet := args[0]
if complet == "bash" {
rootCmd.GenBashCompletion(os.Stdout)
}else if complet == "zsh" {
rootCmd.GenZshCompletion(os.Stdout)
} else if complet == "zsh" {
zsh.Wrap(rootCmd).GenZshCompletion(os.Stdout)
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module github.com/sunny0826/kubecm
go 1.12

require (
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/bndr/gotabulate v1.1.2
github.com/gogo/protobuf v1.2.1 // indirect
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/manifoldco/promptui v0.3.2
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/rsteube/cobra-zsh-gen v1.1.0
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20190313235455-40a48860b5ab // indirect
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1
Expand Down
Loading

0 comments on commit b113301

Please sign in to comment.