forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
completions.go
72 lines (61 loc) · 2.46 KB
/
completions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"os"
"github.com/spf13/cobra"
)
var (
completionLong = `Output shell completion code for the specified shell.
The shell code must be evaluated to provide interactive completions
of openshift-install commands.
For examples of loading/evaluating the completions see:
openshift-install completion bash --help`
completionExampleBash = ` # 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 you've installed via other means, you may need add the completion to your completion directory
openshift-install completion bash > $(brew --prefix)/etc/bash_completion.d/openshift-install
# Installing bash completion on Linux
## Load the openshift-install completion code for bash into the current shell
source <(openshift-install completion bash)
## Write bash completion code to a file and source it from .bash_profile
openshift-install completion bash > ~/.openshift-install/completion.bash.inc
printf "
# Kubectl shell completion
source '$HOME/.openshift-install/completion.bash.inc'
" >> $HOME/.bash_profile
source $HOME/.bash_profile`
completionExampleZsh = `# Load the openshift-install completion code for zsh[1] into the current shell
source <(openshift-install completion zsh)
# Set the openshift-install completion code for zsh[1] to autoload on startup
openshift-install completion zsh > "${fpath[1]}/_openshift-install"`
)
func newCompletionCmd() *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Outputs shell completions for the openshift-install command",
Long: completionLong,
}
bashCompletionCmd := &cobra.Command{
Use: "bash",
Short: "Outputs the bash shell completions",
Example: completionExampleBash,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Root().GenBashCompletion(os.Stdout)
},
}
completionCmd.AddCommand(bashCompletionCmd)
// The zsh completions didn't work for crawford, so commenting them out
//zshCompletionCmd := &cobra.Command{
//Use: "zsh",
//Short: "Outputs the zsh shell completions",
//Example: completionExampleZsh,
//RunE: func(cmd *cobra.Command, _ []string) error {
//return cmd.Root().GenZshCompletion(os.Stdout)
//},
//}
//completionCmd.AddCommand(zshCompletionCmd)
return completionCmd
}