-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (66 loc) · 1.36 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 (
"fmt"
"log"
"os"
"path/filepath"
"strings"
)
func run() error {
args := os.Args[1:]
if len(args) < 1 {
args = []string{""}
}
log.SetPrefix("| ")
log.SetFlags(log.Flags() | log.Lmsgprefix)
switch strings.ToLower(args[0]) {
case "dump":
if len(args) < 2 {
return fmt.Errorf("session-cookie is missing")
}
session := args[1]
testName := ""
if len(args) >= 3 {
testName = args[2]
}
tests, err := dump(session, testName)
if err != nil {
return err
}
if testName == "" {
var b strings.Builder
b.WriteString("test is missing, select one:")
for _, test := range tests {
b.WriteRune('\n')
b.WriteString(strings.ToLower(test.VendorTest))
}
return fmt.Errorf("%s", b.String())
}
return nil
case "produce":
if len(args) < 2 {
var b strings.Builder
entries, err := os.ReadDir(filepath.Join("out", "dump"))
if err != nil {
return err
}
b.WriteString("test is missing, select one:")
for _, entry := range entries {
if entry.IsDir() {
b.WriteRune('\n')
b.WriteString(strings.ToLower(entry.Name()))
}
}
return fmt.Errorf("%s", b.String())
}
testName := args[1]
return produce(testName)
default:
return fmt.Errorf("first argument must be 'dump' or 'produce'")
}
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}