This repository was archived by the owner on May 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbroforce.go
More file actions
69 lines (56 loc) · 1.5 KB
/
broforce.go
File metadata and controls
69 lines (56 loc) · 1.5 KB
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
package main
import (
"fmt"
"os"
"runtime"
"strings"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/InnovaCo/broforce/bus"
"github.com/InnovaCo/broforce/config"
"github.com/InnovaCo/broforce/logger"
"github.com/InnovaCo/broforce/tasks"
)
var version = "0.5.0"
func main() {
cfgPath := kingpin.Flag("config", "Path to config.yml file.").Default("config.yml").String()
show := kingpin.Flag("show", "Show all task names.").Bool()
allow := kingpin.Flag("allow", "list of allowed tasks").Default(tasks.GetPoolString()).String()
kingpin.Version(version)
kingpin.Parse()
if *show {
fmt.Println("name bus adapters:")
for _, n := range bus.GetNameAdapters() {
fmt.Println(" - ", n)
}
fmt.Println("task names:")
for n := range tasks.GetPool() {
fmt.Println(" - ", n)
}
return
}
if _, err := os.Stat(*cfgPath); os.IsNotExist(err) {
fmt.Errorf("%v", err)
return
}
allowTasks := fmt.Sprintf(",%s,", *allow)
c := config.New(*cfgPath, config.YAMLAdapter)
if c == nil {
fmt.Println("Error: config not create")
return
}
logger.New(c.Get("logger"))
logger.Log.Debugf("Config for bus: %v", c.Get("bus"))
b := bus.New(c.Get("bus"))
for n, s := range tasks.GetPool() {
if strings.Index(allowTasks, fmt.Sprintf(",%s,", n)) != -1 {
logger.Log.Debugf("Config for %s: %v", n, c.Get(n))
go bus.SafeRun(s.Run, bus.SafeParams{Retry: 0, Delay: 0})(
bus.Context{
Name: n,
Config: c.Get(n),
Log: logger.Logger4Handler(n, ""),
Bus: b})
}
}
runtime.Goexit()
}