github.com/saucelabs/saucectl@v0.175.1/internal/cmd/completion/cmd.go (about)

     1  package completion
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/spf13/cobra"
     7  )
     8  
     9  // Command creates the `completion` command
    10  func Command() *cobra.Command {
    11  	var cmd = &cobra.Command{
    12  		Use:   "completion [bash|zsh|fish|powershell]",
    13  		Short: "Generate completion script",
    14  		Long: `To load completions:
    15  
    16  Bash:
    17  
    18    $ source <(saucectl completion bash)
    19  
    20    # To load completions for each session, execute once:
    21    # Linux:
    22    $ saucectl completion bash > /etc/bash_completion.d/saucectl
    23    # macOS:
    24    $ saucectl completion bash > /usr/local/etc/bash_completion.d/saucectl
    25  
    26  Zsh:
    27  
    28    # If shell completion is not already enabled in your environment,
    29    # enable it by executing the following once:
    30  
    31    $ echo "autoload -U compinit; compinit" >> ~/.zshrc
    32  
    33    # To load completions for each session, execute once:
    34    $ saucectl completion zsh > "${fpath[1]}/_saucectl"
    35  
    36    # Start a new shell to apply this setup.
    37  
    38  fish:
    39  
    40    $ saucectl completion fish | source
    41  
    42    # To load completions for each session, execute once:
    43    $ saucectl completion fish > ~/.config/fish/completions/saucectl.fish
    44  
    45  PowerShell:
    46  
    47    PS> saucectl completion powershell | Out-String | Invoke-Expression
    48  
    49    # To load completions for every new session, 
    50    # run the following and then source this file from your Powershell profile:
    51    PS> saucectl completion powershell > saucectl.ps1
    52  `,
    53  		DisableFlagsInUseLine: true,
    54  		SilenceUsage:          true,
    55  		ValidArgs:             []string{"bash", "zsh", "fish", "powershell"},
    56  		Args:                  cobra.ExactValidArgs(1),
    57  		Run: func(cmd *cobra.Command, args []string) {
    58  			switch args[0] {
    59  			case "bash":
    60  				_ = cmd.Root().GenBashCompletion(os.Stdout)
    61  			case "zsh":
    62  				_ = cmd.Root().GenZshCompletion(os.Stdout)
    63  			case "fish":
    64  				_ = cmd.Root().GenFishCompletion(os.Stdout, true)
    65  			case "powershell":
    66  				_ = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
    67  			}
    68  		},
    69  	}
    70  
    71  	return cmd
    72  }