-
Notifications
You must be signed in to change notification settings - Fork 0
/
qapi.go
55 lines (43 loc) · 986 Bytes
/
qapi.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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/codingconcepts/qapi/models"
"github.com/codingconcepts/qapi/runner"
"gopkg.in/yaml.v3"
)
var version string
func main() {
log.SetFlags(0)
configPath := flag.String("config", "", "absolute or relative path to a config file")
showVersion := flag.Bool("version", false, "show the version")
flag.Parse()
if *showVersion {
log.Println(version)
os.Exit(0)
}
if *configPath == "" {
flag.Usage()
os.Exit(2)
}
if err := runFile(*configPath); err != nil {
log.Fatalf("error running file: %v", err)
}
}
func runFile(path string) error {
configFile, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("reading config file: %w", err)
}
var c models.Config
if err := yaml.Unmarshal(configFile, &c); err != nil {
return fmt.Errorf("parsing config file: %w", err)
}
r := runner.New(&c)
if err = r.Start(); err != nil {
return fmt.Errorf("executing runner: %w", err)
}
return nil
}