You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.0 KiB
58 lines
1.0 KiB
package config
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"encoding/json"
|
|
"regexp"
|
|
)
|
|
|
|
type Process struct {
|
|
Command string
|
|
Args []string
|
|
ExecCmd *exec.Cmd
|
|
}
|
|
|
|
type Config struct {
|
|
Triggers []string
|
|
Includes []string
|
|
Processes map[string]Process
|
|
StartingHP int
|
|
|
|
ConfigPath string
|
|
BuildRunning bool
|
|
TriggerRegex []*regexp.Regexp
|
|
IncludeRegex []*regexp.Regexp
|
|
|
|
HP int
|
|
Errors int
|
|
}
|
|
|
|
var Settings Config
|
|
|
|
func ParseFlags(c *Config) {
|
|
flag.StringVar(&c.ConfigPath, "config", ".ttarpit.json", ".ttarpit.json to load")
|
|
flag.Parse()
|
|
}
|
|
|
|
func Load() {
|
|
ParseFlags(&Settings)
|
|
|
|
data, err := os.ReadFile(Settings.ConfigPath)
|
|
if err != nil { log.Fatal(err) }
|
|
|
|
err = json.Unmarshal(data, &Settings)
|
|
if err != nil { log.Fatal(err) }
|
|
|
|
for _, reg := range Settings.Triggers {
|
|
Settings.TriggerRegex = append(Settings.TriggerRegex, regexp.MustCompile(reg))
|
|
}
|
|
|
|
for _, reg := range Settings.Includes {
|
|
Settings.IncludeRegex = append(Settings.IncludeRegex, regexp.MustCompile(reg))
|
|
}
|
|
|
|
Settings.HP = Settings.StartingHP
|
|
}
|
|
|