github.com/vishnupahwa/lakctl@v0.0.2-alpha/cmd/commands/completion.go (about)

     1  package commands
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/spf13/cobra"
     7  )
     8  
     9  func addCompletion(topLevel *cobra.Command) {
    10  	var zsh bool
    11  	// completionCmd represents the completion command
    12  	var completionCmd = &cobra.Command{
    13  		Use:   "completion",
    14  		Short: "Generates bash completion scripts",
    15  		RunE: func(cmd *cobra.Command, args []string) error {
    16  			if zsh {
    17  				return topLevel.GenZshCompletion(os.Stdout)
    18  			}
    19  			return topLevel.GenBashCompletion(os.Stdout)
    20  		},
    21  	}
    22  	completionCmd.Flags().BoolVar(&zsh, "zsh", false, "Output zsh completion instead")
    23  	topLevel.AddCommand(completionCmd)
    24  }