func Generate(cmd *cobra.Command, args []string) error {
	if len(args) == 0 {
		return fmt.Errorf("shell not specified. ex. kompose completion [bash|zsh|fish]")
	}
	if len(args) > 1 {
		return fmt.Errorf("too many arguments. Expected only the shell type. ex. kompose completion [bash|zsh|fish]")
	}
	switch args[0] {
	case "bash":
		return cmd.Root().GenBashCompletion(os.Stdout)
	case "zsh":
		return runCompletionZsh(os.Stdout, cmd.Root())
	case "fish":
		return runCompletionFish(os.Stdout, cmd.Root())
	default:
		return fmt.Errorf("not a compatible shell, bash, zsh and fish are only supported")
	}
}
Generate the appropriate autocompletion file
package cmd
import (
	"bytes"
	"fmt"
	"io"
	"os"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)
var completion = &cobra.Command{
	Use:   "completion SHELL",
	Short: "Output shell completion code",
	Long: `Generates shell completion code.
Auto completion supports bash, zsh and fish. Output is to STDOUT.
source <(kompose completion bash)
source <(kompose completion zsh)
kompose completion fish | source
Will load the shell completion code.
	`,
	RunE: func(cmd *cobra.Command, args []string) error {
		err := Generate(cmd, args)
		if err != nil {
			log.Fatalf("Error: %s", err)
		}
		return nil
	},
}