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 root := commands.NewRootCommand()
18
19 tasks := map[string]func(*cobra.Command) error{
20 "Bash": genBash,
21 "Fish": genFish,
22 "PowerShell": genPowerShell,
23 "ZSH": genZsh,
24 }
25
26 var wg sync.WaitGroup
27 for name, f := range tasks {
28 wg.Add(1)
29 go func(name string, f func(*cobra.Command) error) {
30 defer wg.Done()
31 err := f(root)
32 if err != nil {
33 fmt.Printf(" - %s: %v\n", name, err)
34 return
35 }
36 fmt.Printf(" - %s: ok\n", name)
37 }(name, f)
38 }
39
40 wg.Wait()
41}
42
43func genBash(root *cobra.Command) error {
44 cwd, _ := os.Getwd()
45 dir := path.Join(cwd, "misc", "bash_completion", "git-bug")
46 return root.GenBashCompletionFile(dir)
47}
48
49func genFish(root *cobra.Command) error {
50 cwd, _ := os.Getwd()
51 dir := path.Join(cwd, "misc", "fish_completion", "git-bug")
52 return root.GenFishCompletionFile(dir, true)
53}
54
55func genPowerShell(root *cobra.Command) error {
56 cwd, _ := os.Getwd()
57 filepath := path.Join(cwd, "misc", "powershell_completion", "git-bug")
58 return root.GenPowerShellCompletionFile(filepath)
59}
60
61func genZsh(root *cobra.Command) error {
62 cwd, _ := os.Getwd()
63 filepath := path.Join(cwd, "misc", "zsh_completion", "git-bug")
64 return root.GenZshCompletionFile(filepath)
65}