-
Notifications
You must be signed in to change notification settings - Fork 0
/
gopac.go
77 lines (67 loc) · 1.44 KB
/
gopac.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"
"github.com/urfave/cli"
)
type GoConfig struct {
Pkgs []GoPkg `toml:pkgs`
}
type GoPkg struct {
Repo string `toml:repo`
OnZshSource *string `toml:onZshSource`
OnZshComp *string `toml:onZshComp`
}
func install_go(pkg GoPkg, isFin chan bool, wg *sync.WaitGroup) {
defer wg.Done()
// install
fmt.Println(pkg.Repo)
cmd := exec.Command("go", "get", "-u", "github.com/"+pkg.Repo)
cmd.Env = os.Environ()
err := cmd.Run()
if err != nil {
fmt.Println(err)
}
if pkg.OnZshComp != nil {
install_zsh_completion(pkg.Repo, *(pkg.OnZshComp))
}
if pkg.OnZshSource != nil {
install_zsh_source(pkg.Repo, *(pkg.OnZshSource))
}
isFin <- true
}
func InstallGo(_ *cli.Context) {
os.Setenv("GOPATH", PAC_HOME)
os.Setenv("GOBIN", filepath.Join(PAC_HOME, "bin"))
wg := new(sync.WaitGroup)
isFin := make(chan bool, len(CONFIG.Go.Pkgs))
for _, pkg := range CONFIG.Go.Pkgs {
wg.Add(1)
go install_go(pkg, isFin, wg)
}
wg.Wait()
close(isFin)
fmt.Println("Installed Go Packages")
}
func init() {
command := cli.Command{
Name: "go",
Usage: "Install or Update Go Packages",
Subcommands: []cli.Command{
{
Name: "update",
Usage: "Update Installed Packages (same as install)",
Action: InstallGo,
},
{
Name: "install",
Usage: "Install Packages from source",
Action: InstallGo,
},
},
}
APP.Commands = append(APP.Commands, command)
}