driftctl/pkg/cmd/completion.go

32 lines
913 B
Go
Raw Normal View History

2021-01-20 13:04:33 +00:00
package cmd
import (
"github.com/spf13/cobra"
)
func NewCompletionCmd() *cobra.Command {
var cmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: "Generate completion script for various shells",
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
switch args[0] {
case "bash":
2021-01-22 10:10:11 +00:00
return cmd.Root().GenBashCompletion(cmd.OutOrStdout())
2021-01-20 13:04:33 +00:00
case "zsh":
2021-01-22 10:10:11 +00:00
return cmd.Root().GenZshCompletion(cmd.OutOrStdout())
2021-01-20 13:04:33 +00:00
case "fish":
2021-01-22 10:10:11 +00:00
return cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true)
2021-01-20 13:04:33 +00:00
case "powershell":
2021-01-22 10:10:11 +00:00
return cmd.Root().GenPowerShellCompletion(cmd.OutOrStdout())
default:
return nil
2021-01-20 13:04:33 +00:00
}
},
}
return cmd
}