-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotter.go
88 lines (71 loc) · 1.91 KB
/
gotter.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
package main
import (
"errors"
"os"
"github.com/codegangsta/cli"
"github.com/op/go-logging"
)
const (
PENDING = iota
FAIL
SUCCESS
// TODO - DEFAULT_CONF_LOCATION = "/etc/gotter/gotter.conf"
)
var (
exitStatus int
log = logging.MustGetLogger("gotter")
WORKSPACE = os.Getenv("WORKSPACE")
GOPATH = os.Getenv("GOPATH")
)
func main() {
initLogger()
app := cli.NewApp()
app.Name = "gotter"
app.Author = "John-Alan Simmons <[email protected]>"
app.Usage = "Utlity to unify and manage Go projects into a single workspace"
app.Version = "0.1.0-rc2"
// Overwrite default 'version' shorthand 'v' flag
cli.VersionFlag.Name = "version"
app.Flags = []cli.Flag{
cli.BoolFlag{"verbose, v", "Enable verbose logging"},
cli.BoolFlag{"extra-verbose, vv", "Enable more verbose logging"},
}
app.Before = func(c *cli.Context) error {
cmd := c.Args().First()
if cmd == "" || cmd == "help" || cmd == "h" {
return nil
}
if c.Bool("extra-verbose") {
logging.SetLevel(logging.DEBUG, "gotter")
} else if c.Bool("verbose") {
logging.SetLevel(logging.INFO, "gotter")
} else {
logging.SetLevel(logging.WARNING, "gotter")
}
// Make sure environment variable is set
if WORKSPACE == "" {
log.Error("[ERROR]: WORKSPACE enviroment variable not set!")
return errors.New("WORKSPACE enviroment variable not set!")
}
if GOPATH == "" {
log.Error("[ERROR]: GOPATH enviroment variable not set!")
return errors.New("GOPATH enviroment variable not set!")
}
return nil
}
app.Commands = []cli.Command{getCommand, cloneCommand, linkCommand, updateRemoteCommand, rmCommand, newCommand}
defer func() {
if exitStatus == FAIL {
log.Error("Status: FAILED")
}
}()
app.Run(os.Args)
}
func initLogger() {
logBackend := logging.NewLogBackend(os.Stderr, "", 0)
syslogBackend, err := logging.NewSyslogBackend("")
if err != nil {
panic(err)
}
logging.SetBackend(logBackend, syslogBackend)
}