-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (58 loc) · 1.14 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
package main
import (
"flag"
"log"
"os"
"commands-orchestration/play"
"commands-orchestration/updater"
"gopkg.in/yaml.v3"
)
var (
version string
commit string
date string
)
func printVersion() {
log.Printf("Version: %s, Commit: %s, Date: %s", version, commit, date)
}
func printUsage() {
log.Print("Specify config path")
log.Print("Usage: ", os.Args[0], " [config path]")
flag.Usage()
}
func readConfig(path string) *play.Play {
data, err := os.ReadFile(path)
if err != nil {
log.Fatalf("error: %v", err)
}
var p play.Play
err = yaml.Unmarshal(data, &p)
if err != nil {
log.Fatalf("error: %v", err)
}
pl := play.NewPlay(p.Stages, p.Vars)
return pl
}
func main() {
v := flag.Bool("v", false, "Print version end exit")
update := flag.Bool("u", false, "Check if newer version is available and self-update")
verbose := flag.Bool("vv", false, "Verbose output")
flag.Parse()
if *v {
printVersion()
return
}
if *update {
updater.DoSelfUpdate(version)
return
}
if len(os.Args) < 2 {
printUsage()
printVersion()
return
}
pl := readConfig(flag.Arg(0))
pl.Run(*verbose)
pl.DumpLogs()
pl.PrintResults()
}