-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (46 loc) · 1.21 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
package main
import (
"embed"
"flag"
helpers "github.com/point-c/generator-helpers"
"html/template"
)
//go:embed *.gotmpl
var templates embed.FS
const (
mainTemplate = "keys.gotmpl"
testTemplate = "keys_test.gotmpl"
)
var args = struct {
config string
out string
tout string
pkg string
}{
config: "keys.yml",
out: helpers.OutputFilename(helpers.EnvGoFile()),
tout: helpers.TestOutputFilename(helpers.EnvGoFile()),
pkg: helpers.EnvGoPackage(),
}
func init() {
flag.StringVar(&args.config, "config", args.config, "events config file")
flag.StringVar(&args.out, "out", args.out, "output filename")
flag.StringVar(&args.tout, "tout", args.tout, "test output filename")
flag.StringVar(&args.pkg, "pkg", args.pkg, "gopackage of output")
}
func main() {
flag.Parse()
Generate(&Dot{
Package: args.pkg,
Keys: helpers.Must(helpers.UnmarshalYAML[map[string]string](args.config)),
})
}
func Generate(d *Dot) {
tmpl := helpers.NewTemplate[*template.Template](templates, nil)
helpers.Generate[*template.Template, *Dot](tmpl, d, mainTemplate, args.out)
helpers.Generate[*template.Template, *Dot](tmpl, d, testTemplate, args.tout)
}
type Dot struct {
Package string
Keys map[string]string
}