...

Source file src/github.com/in-toto/in-toto-golang/cmd/completion.go

Documentation: github.com/in-toto/in-toto-golang/cmd

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

View as plain text