-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
90 lines (71 loc) · 1.32 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
86
87
88
89
90
package main
import (
"context"
"fmt"
"io/ioutil"
"log"
"math/rand"
"os"
"time"
"github.com/alexflint/go-arg"
"github.com/cirocosta/cr/lib"
"github.com/rs/zerolog"
)
var version string = "dev"
type cliArgs struct {
lib.Runtime
}
func (r cliArgs) Version() string {
return "cr - the concurrent runner - version=" + version
}
var (
args = &cliArgs{
lib.Runtime{
File: "./.cr.yml",
LogsDirectory: "/tmp",
Stdout: false,
Graph: false,
},
}
logger = zerolog.New(os.Stdout).
With().
Str("from", "main").
Logger()
ui = lib.NewUi()
)
func must(err error) {
if err == nil {
return
}
logger.Fatal().
Err(err).
Msg("main execution failed")
}
func main() {
arg.MustParse(args)
rand.Seed(time.Now().UnixNano())
log.SetOutput(ioutil.Discard)
cfg, err := lib.ConfigFromFile(args.File)
must(err)
cfg.OnJobStatusChange = func(a *lib.Activity) {
ui.WriteActivity(a)
}
if cfg.Runtime.LogsDirectory == "" {
cfg.Runtime.LogsDirectory = args.LogsDirectory
}
if args.Stdout {
cfg.Runtime.Stdout = true
}
executor, err := lib.New(&cfg)
must(err)
if args.Graph {
fmt.Println(executor.GetDotGraph())
os.Exit(0)
}
fmt.Printf(`
Starting execution.
Logs directory: %s
`+"\n", cfg.Runtime.LogsDirectory)
err = executor.Execute(context.Background())
must(err)
}