forked from gojuno/genval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (34 loc) · 982 Bytes
/
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
package main
//go:generate genval examples/simple
//go:generate genval examples/overriding
//go:generate genval examples/complicated
import (
"flag"
"log"
"os"
)
func main() {
outputFilePtr := flag.String("outputFile", "validators.go", "output file name")
needValidatableCheckPtr := flag.Bool("needValidatableCheck", true, "check struct on Validatable before calling Validate()")
flag.Parse()
args := flag.Args()
if len(args) > 1 {
flag.PrintDefaults()
os.Exit(1)
}
dir := "api"
if len(args) == 1 {
dir = args[0]
}
mainLogic(dir, *outputFilePtr, *needValidatableCheckPtr)
}
func mainLogic(dir string, outputFile string, needCheck bool) {
insp := NewInspector()
if err := insp.Inspect(dir, outputFile); err != nil {
log.Fatalf("unable to inspect structs for %q: %v", dir, err)
}
g := NewGenerator(insp.Result())
if err := g.Generate(dir, outputFile, needCheck); err != nil {
log.Fatalf("unable to generate validators for %q: %v", dir, err)
}
}