github.com/go-swagger/go-swagger@v0.31.0/generator/templates/cli/completion.gotmpl (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  
     4  {{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }}
     5  
     6  
     7  package {{ .GenOpts.CliPackage }}
     8  
     9  // This file was generated by the swagger tool.
    10  // Editing this file might prove futile when you re-run the swagger generate command
    11  
    12  import(
    13      "github.com/spf13/cobra"
    14  )
    15  
    16  func makeGenCompletionCmd() *cobra.Command{
    17  
    18      var completionCmd = &cobra.Command{
    19          Use:   "completion [bash|zsh|fish|powershell]",
    20          Short: "Generate completion script",
    21          Long: `To load completions:
    22  
    23  Bash:
    24  
    25    $ source <(yourprogram completion bash)
    26  
    27    # To load completions for each session, execute once:
    28    # Linux:
    29    $ yourprogram completion bash > /etc/bash_completion.d/yourprogram
    30    # macOS:
    31    $ yourprogram completion bash > /usr/local/etc/bash_completion.d/yourprogram
    32  
    33  Zsh:
    34  
    35    # If shell completion is not already enabled in your environment,
    36    # you will need to enable it.  You can execute the following once:
    37  
    38    $ echo "autoload -U compinit; compinit" >> ~/.zshrc
    39  
    40    # To load completions for each session, execute once:
    41    $ yourprogram completion zsh > "${fpath[1]}/_yourprogram"
    42  
    43    # You will need to start a new shell for this setup to take effect.
    44  
    45  fish:
    46  
    47    $ yourprogram completion fish | source
    48  
    49    # To load completions for each session, execute once:
    50    $ yourprogram completion fish > ~/.config/fish/completions/yourprogram.fish
    51  
    52  PowerShell:
    53  
    54    PS> yourprogram completion powershell | Out-String | Invoke-Expression
    55  
    56    # To load completions for every new session, run:
    57    PS> yourprogram completion powershell > yourprogram.ps1
    58    # and source this file from your PowerShell profile.
    59  `,
    60          DisableFlagsInUseLine: true,
    61          ValidArgs:             []string{"bash", "zsh", "fish", "powershell"},
    62          Args:                  cobra.ExactValidArgs(1),
    63          Run: func(cmd *cobra.Command, args []string) {
    64              switch args[0] {
    65              case "bash":
    66                  cmd.Root().GenBashCompletion(os.Stdout)
    67              case "zsh":
    68                  cmd.Root().GenZshCompletion(os.Stdout)
    69              case "fish":
    70                  cmd.Root().GenFishCompletion(os.Stdout, true)
    71              case "powershell":
    72                  cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
    73              }
    74          },
    75      }
    76      return completionCmd
    77  }