-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatcher_generator.go
65 lines (48 loc) · 1.46 KB
/
matcher_generator.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
// The following directive is necessary to make the package coherent:
// build ignore
// This program generates matchers It can be invoked by running
// go generate
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"text/template"
"github.com/jessevdk/go-flags"
"github.com/vanilla-rtb/extensions/codegen"
"log"
"reflect"
"stubs"
)
func die(err error) {
if err != nil {
log.Fatal(err)
}
}
type Options struct {
InputTemplate flags.Filename `short:"i" long:"input-template" description:"InputTemplate file" default:"-"`
OutputDir flags.Filename `short:"o" long:"output-dir" description:"OutputDir file" default:"-"`
}
var options Options
var parser = flags.NewParser(&options, flags.Default)
func main() {
for k,_ := range stubs.TypeRegistry {
fmt.Println(k)
}
_, err := parser.Parse()
die(err)
templateContent, err := ioutil.ReadFile(string(options.InputTemplate))
die(err)
var matcherTemplate = template.Must(template.New("").Funcs(codegen.FuncMap).Parse(string(templateContent)))
for _,value := range stubs.TypeRegistry {
gen := codegen.NewCodeGenerator(reflect.New(value).Elem().Interface(), matcherTemplate, )
outFileName := strings.Join([]string{string(options.OutputDir), strings.Join([]string{gen.GeneratedBasicName, ".hpp"}, "")}, "/")
f, err := os.Create(outFileName)
die(err)
defer f.Close()
//Generate code
err = gen.Execute(f)
die(err)
}
}