-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmain.go
88 lines (73 loc) · 2.13 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
80
81
82
83
84
85
86
87
88
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/MarcGrol/golangAnnotations/generator"
"github.com/MarcGrol/golangAnnotations/generator/ast"
"github.com/MarcGrol/golangAnnotations/generator/event"
"github.com/MarcGrol/golangAnnotations/generator/eventService"
"github.com/MarcGrol/golangAnnotations/generator/jsonHelpers"
"github.com/MarcGrol/golangAnnotations/generator/repository"
"github.com/MarcGrol/golangAnnotations/generator/rest"
"github.com/MarcGrol/golangAnnotations/model"
"github.com/MarcGrol/golangAnnotations/parser"
)
const (
version = "0.8"
excludeMatchPattern = "^" + generator.GenfilePrefix + ".*.go$"
)
var inputDir *string
func main() {
processArgs()
parsedSources, err := parser.New().ParseSourceDir(*inputDir, "^.*.go$", excludeMatchPattern)
if err != nil {
log.Printf("Error parsing golang sources in %s: %s", *inputDir, err)
os.Exit(1)
}
runAllGenerators(*inputDir, parsedSources)
os.Exit(0)
}
func runAllGenerators(inputDir string, parsedSources model.ParsedSources) {
for name, g := range map[string]generator.Generator{
"ast": ast.NewGenerator("ast.json"),
"event": event.NewGenerator(),
"event-service": eventService.NewGenerator(),
"json-helpers": jsonHelpers.NewGenerator(),
"rest": rest.NewGenerator(),
"repository": repository.NewGenerator(),
} {
err := g.Generate(inputDir, parsedSources)
if err != nil {
log.Printf("Error generating module %s: %s", name, err)
os.Exit(-1)
}
}
}
func printUsage() {
fmt.Fprintf(os.Stderr, "\nUsage:\n")
fmt.Fprintf(os.Stderr, " %s [flags]\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n")
os.Exit(1)
}
func printVersion() {
fmt.Fprintf(os.Stderr, "\nVersion: %s\n", version)
os.Exit(1)
}
func processArgs() {
inputDir = flag.String("input-dir", "", "Directory to be examined")
help := flag.Bool("help", false, "Usage information")
version := flag.Bool("version", false, "Version information")
flag.Parse()
if help != nil && *help == true {
printUsage()
}
if version != nil && *version == true {
printVersion()
}
if inputDir == nil || *inputDir == "" {
printUsage()
}
}