-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
85 lines (71 loc) · 2.27 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
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"flag"
"fmt"
"os"
log "github.com/Sirupsen/logrus"
)
var (
// Must be set at build time
Version string = "UNDEFINED"
GitSHA string = "UNDEFINED"
configFile string
metadataVersion string
logLevel string
checkCmd string
notifyCmd string
onetime bool
showVersion bool
notifyOutput bool
includeInactive bool
interval int
)
func init() {
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
log.SetOutput(os.Stdout)
flag.StringVar(&configFile, "config", "", "Path to optional config file")
flag.StringVar(&metadataVersion, "metadata-version", "latest", "Metadata version to use for querying the Metadata API")
flag.IntVar(&interval, "interval", 60, "Interval (in seconds) for polling the Metadata API for changes")
flag.BoolVar(&includeInactive, "include-inactive", false, "Not yet implemented")
flag.BoolVar(&onetime, "onetime", false, "Process all templates once and exit")
flag.StringVar(&logLevel, "log-level", "info", "Verbosity of log output (debug,info,warn,error)")
flag.StringVar(&checkCmd, "check-cmd", "", "Command to check the content before updating the destination file.")
flag.StringVar(¬ifyCmd, "notify-cmd", "", "Command to run after the destination file has been updated.")
flag.BoolVar(¬ifyOutput, "notify-output", false, "Print the result of the notify command to STDOUT")
flag.BoolVar(&showVersion, "version", false, "Show application version and exit")
flag.Usage = printUsage
flag.Parse()
}
func printUsage() {
fmt.Println(`Usage: rancher-gen [options] source [destination]
Options:`)
flag.VisitAll(func(fg *flag.Flag) {
fmt.Printf("\t--%s=%s\n\t\t%s\n", fg.Name, fg.DefValue, fg.Usage)
})
fmt.Println(`
Arguments:
source - Path to the template file
dest - Path to the output file. If ommited result is printed to STDOUT.`)
}
func main() {
if showVersion {
fmt.Printf("rancher-gen version %s (%s) \n", Version, GitSHA)
os.Exit(0)
}
if flag.NArg() < 1 && len(configFile) == 0 {
flag.Usage()
os.Exit(1)
}
log.Infof("Starting rancher-gen %s (%s)", Version, GitSHA)
conf, err := initConfig()
if err != nil {
log.Fatal(err.Error())
}
r, err := NewRunner(conf)
if err != nil {
log.Fatal(err.Error())
}
if err := r.Run(); err != nil {
log.Fatal(err)
}
}