1package main
2
3import (
4 "fmt"
5 "os"
6 "path"
7 "sync"
8
9 "github.com/spf13/cobra"
10
11 "github.com/MichaelMure/git-bug/commands"
12)
13
14func main() {
15 fmt.Println("Generating completion files ...")
16
17 tasks := map[string]func(*cobra.Command) error{
18 "Bash": genBash,
19 "Fish": genFish,
20 "PowerShell": genPowerShell,
21 "ZSH": genZsh,
22 }
23
24 var wg sync.WaitGroup
25 for name, f := range tasks {
26 wg.Add(1)
27 go func(name string, f func(*cobra.Command) error) {
28 defer wg.Done()
29 root := commands.NewRootCommand()
30 err := f(root)
31 if err != nil {
32 fmt.Printf(" - %s: %v\n", name, err)
33 return
34 }
35 fmt.Printf(" - %s: ok\n", name)
36 }(name, f)
37 }
38
39 wg.Wait()
40}
41
42func genBash(root *cobra.Command) error {
43 cwd, _ := os.Getwd()
44 dir := path.Join(cwd, "misc", "bash_completion", "git-bug")
45 return root.GenBashCompletionFile(dir)
46}
47
48func genFish(root *cobra.Command) error {
49 cwd, _ := os.Getwd()
50 dir := path.Join(cwd, "misc", "fish_completion", "git-bug")
51 return root.GenFishCompletionFile(dir, true)
52}
53
54func genPowerShell(root *cobra.Command) error {
55 cwd, _ := os.Getwd()
56 filepath := path.Join(cwd, "misc", "powershell_completion", "git-bug")
57 return root.GenPowerShellCompletionFile(filepath)
58}
59
60func genZsh(root *cobra.Command) error {
61 cwd, _ := os.Getwd()
62 filepath := path.Join(cwd, "misc", "zsh_completion", "git-bug")
63 return root.GenZshCompletionFile(filepath)
64}