-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (38 loc) · 793 Bytes
/
main.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
package main
import (
"flag"
"log"
"os"
"os/exec"
"path/filepath"
"github.com/constabulary/gb/cmd"
)
func main() {
var projectdir string
var update bool
flag.StringVar(&projectdir, "p", os.Getenv("GB_PROJECT_DIR"), "project directory")
flag.BoolVar(&update, "u", false, "run with `go get -u`")
flag.Parse()
vendor := filepath.Join(projectdir, "vendor")
env := cmd.MergeEnv(os.Environ(), map[string]string{
"GOPATH": vendor,
})
gotool, err := exec.LookPath("go")
if err != nil {
log.Fatal(err)
}
args := []string{"go", "get", "-d"}
if update {
args = append(args, "-u")
}
cmd := exec.Cmd{
Path: gotool,
Args: append(args, flag.Args()...),
Env: env,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}