| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package completion |
| 5 |
|
| 6 |
import ( |
| 7 |
"os" |
| 8 |
|
| 9 |
"github.com/spf13/cobra" |
| 10 |
) |
| 11 |
|
| 12 |
func NewCommand() *cobra.Command { |
| 13 |
return &cobra.Command{ |
| 14 |
Use: "completion [bash|zsh|fish|powershell]", |
| 15 |
Short: "Generate shell completion script", |
| 16 |
Long: "Generate shell completion.", |
| 17 |
DisableFlagsInUseLine: true, |
| 18 |
ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, |
| 19 |
Args: cobra.ExactValidArgs(1), |
| 20 |
RunE: func(cmd *cobra.Command, args []string) error { |
| 21 |
switch args[0] { |
| 22 |
case "bash": |
| 23 |
return cmd.Root().GenBashCompletion(os.Stdout) |
| 24 |
case "zsh": |
| 25 |
return cmd.Root().GenZshCompletion(os.Stdout) |
| 26 |
case "fish": |
| 27 |
return cmd.Root().GenFishCompletion(os.Stdout, true) |
| 28 |
case "powershell": |
| 29 |
return cmd.Root().GenPowerShellCompletion(os.Stdout) |
| 30 |
} |
| 31 |
return nil |
| 32 |
}, |
| 33 |
} |
| 34 |
} |