github.com/openshift/installer@v1.4.17/cmd/openshift-install/completions.go (about)

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