github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/cmd/ddev_gen_autocomplete/ddev_gen_autocomplete.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/ddev/ddev/cmd/ddev/cmd"
     5  	"github.com/ddev/ddev/pkg/util"
     6  	"os"
     7  	"path/filepath"
     8  )
     9  
    10  var targetDir = ".gotmp/bin/completions"
    11  
    12  func main() {
    13  	if _, err := os.Stat(targetDir); os.IsNotExist(err) {
    14  		err = os.MkdirAll(targetDir, 0755)
    15  		util.CheckErr(err)
    16  	}
    17  	err := cmd.RootCmd.GenBashCompletionFileV2(filepath.Join(targetDir, "ddev_bash_completion.sh"), true)
    18  	if err != nil {
    19  		util.Failed("could not generate ddev_bash_completion.sh: %v", err)
    20  	}
    21  	err = cmd.RootCmd.GenZshCompletionFile(filepath.Join(targetDir, "ddev_zsh_completion.sh"))
    22  	if err != nil {
    23  		util.Failed("could not generate ddev_zsh_completion.sh: %v", err)
    24  	}
    25  	err = cmd.RootCmd.GenFishCompletionFile(filepath.Join(targetDir, "ddev_fish_completion.sh"), true)
    26  	if err != nil {
    27  		util.Failed("could not generate ddev_fish_completion.sh: %v", err)
    28  	}
    29  	err = cmd.RootCmd.GenPowerShellCompletionFileWithDesc(filepath.Join(targetDir, "ddev_powershell_completion.ps1"))
    30  	if err != nil {
    31  		util.Failed("could not generate ddev_powershell_completion.ps1: %v", err)
    32  	}
    33  	err = genFigSpecCompletionFile(filepath.Join(targetDir, "ddev_fig_spec.ts"))
    34  	if err != nil {
    35  		util.Failed("could not generate ddev_fig_spec.ts: %v", err)
    36  	}
    37  }