forked from sevagh/goat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (58 loc) · 1.47 KB
/
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
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
package main // import "github.com/sevagh/goat"
import (
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"os"
)
//Goat version substituted by the Makefile
var VERSION string
func main() {
logLevelPtr := flag.String("logLevel", "info", "Log level")
versionPtr := flag.Bool("version", false, "Display version and exit")
debugPtr := flag.Bool("debug", false, "Interactive debug prompts")
tagPrefixPtr := flag.String("tagPrefix", "GOAT-IN", "Prefix for GOAT related tags")
tagPrefixEnv := os.Getenv("GOAT_TAG_PREFIX")
logLevelEnv := os.Getenv("GOAT_LOG_LEVEL")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: goat [OPTIONS] ebs|eni\n\nOPTIONS\n")
flag.PrintDefaults()
}
flag.Parse()
if *versionPtr {
fmt.Println("goat ", VERSION)
os.Exit(0)
}
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
command := flag.Args()[0]
logLevel := ""
if logLevelEnv != "" {
logLevel = logLevelEnv // env var takes precedence
} else {
logLevel = *logLevelPtr
}
tagPrefix := ""
if tagPrefixEnv != "" {
tagPrefix = tagPrefixEnv
} else {
tagPrefix = *tagPrefixPtr
}
log.SetOutput(os.Stderr)
if level, err := log.ParseLevel(logLevel); err != nil {
log.Fatalf("%v", err)
} else {
log.SetLevel(level)
}
log.SetFormatter(&log.TextFormatter{})
log.Printf("Running goat for %s", command)
if command == "ebs" {
GoatEbs(*debugPtr, tagPrefix)
} else if command == "eni" {
GoatEni(*debugPtr, tagPrefix)
} else {
log.Fatalf("Unrecognized command: %s", command)
}
}