This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
forked from mediocregopher/goat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goat.go
104 lines (87 loc) · 2.02 KB
/
goat.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"errors"
"fmt"
"github.com/mediocregopher/goat/env"
"github.com/mediocregopher/goat/exec"
"os"
"syscall"
)
func fatal(err error) {
fmt.Println(err)
os.Exit(1)
}
func printGhelp() {
fmt.Printf(
`Goat is a command-line wrapper for go which handles dependency
management in a sane way. Check the goat docs at github.com/mediocregopher/goat
for a more in-depth overview.
Usage:
%s command [arguments]
The commands are:
deps Read the .go.yaml file for this project and set up dependencies in
the dependencies folder specified (default ".deps"). Recursively
download dependencies wherever a .go.yaml file is encountered
ghelp Show this dialog
All other commands are passed through to the go binary on your system. Try '%s
help' for its available commands
`, os.Args[0], os.Args[0])
os.Exit(0)
}
func main() {
cwd, err := os.Getwd()
if err != nil {
fatal(err)
}
projroot, err := env.FindProjRoot(cwd)
var genv *env.GoatEnv
if err == nil {
genv, err = env.NewGoatEnv(projroot)
if err != nil {
fatal(err)
}
if err = genv.PrependToGoPath(); err != nil {
fatal(err)
}
if err = genv.Setup(); err != nil {
fatal(err)
}
}
args := os.Args[1:]
if len(args) < 1 {
printGhelp()
}
switch args[0] {
case "deps":
if genv != nil {
err := genv.FetchDependencies(genv.AbsDepDir())
if err != nil {
fatal(err)
}
} else {
fatal(errors.New(".go.yaml file not found on current path"))
}
case "ghelp":
printGhelp()
default:
if actualgo, ok := ActualGo(); ok {
err := exec.PipedCmd(actualgo, args...)
if err != nil {
os.Exit(1)
}
} else {
newargs := make([]string, len(args)+1)
copy(newargs[1:], args)
newargs[0] = "go"
err := exec.PipedCmd("/usr/bin/env", newargs...)
if err != nil {
os.Exit(1)
}
}
}
}
// ActualGo returns the GOAT_ACTUALGO environment variable contents, and whether
// or not the variable was actually set
func ActualGo() (string, bool) {
return syscall.Getenv("GOAT_ACTUALGO")
}