forked from lightclient/rpctestgen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
79 lines (65 loc) · 1.6 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
package main
import (
"context"
"fmt"
"os"
"regexp"
"github.com/alexflint/go-arg"
)
const (
HOST string = "127.0.0.1"
PORT string = "13375"
NETWORKPORT string = "13376"
)
type Args struct {
ClientType string `arg:"--client" help:"client type" default:"geth"`
ClientBin string `arg:"--bin" help:"path to client binary" default:"geth"`
OutDir string `arg:"--out" help:"directory where test fixtures will be written" default:"tests"`
ChainDir string `arg:"--chain" help:"path to directory with chain.rlp and genesis.json"`
Verbose bool `arg:"-v,--verbose" help:"verbosity level of rpctestgen"`
LogLevel string `arg:"--loglevel" help:"log level of client" default:"info"`
TestsRegexp string `arg:"--tests" help:"regex of tests to fill" default:".*"`
tests *regexp.Regexp
logLevelInt int
}
type ArgsKey struct{}
var ARGS = ArgsKey{}
func main() {
var args Args
arg.MustParse(&args)
lvl, err := loglevelToInt(args.LogLevel)
if err != nil {
exit(err)
}
args.logLevelInt = lvl
if args.tests, err = regexp.Compile(args.TestsRegexp); err != nil {
exit(err)
}
ctx := context.Background()
ctx = context.WithValue(ctx, ARGS, &args)
if err := runGenerator(ctx); err != nil {
exit(err)
}
}
func exit(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
}
func loglevelToInt(lvl string) (int, error) {
switch lvl {
case "err":
return 1, nil
case "warn":
return 2, nil
case "info":
return 3, nil
case "debug":
return 4, nil
case "trace":
return 5, nil
default:
return 0, fmt.Errorf("unknown log level: %s", lvl)
}
}