forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_v3.go
104 lines (81 loc) · 2.14 KB
/
entry_v3.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"flag"
"github.com/davyxu/tabtoy/v3/compiler"
"github.com/davyxu/tabtoy/v3/gen"
"github.com/davyxu/tabtoy/v3/gen/binpak"
"github.com/davyxu/tabtoy/v3/gen/cssrc"
"github.com/davyxu/tabtoy/v3/gen/gosrc"
"github.com/davyxu/tabtoy/v3/gen/jsontext"
"github.com/davyxu/tabtoy/v3/gen/luasrc"
"github.com/davyxu/tabtoy/v3/helper"
"github.com/davyxu/tabtoy/v3/model"
"github.com/davyxu/tabtoy/v3/report"
"os"
)
type V3GenEntry struct {
name string
f gen.GenFunc
flagstr *string
}
// v3新增
var (
paramIndexFile = flag.String("index", "", "input multi-files configs")
paramUseGBKCSV = flag.Bool("use_gbkcsv", true, "use gbk format in csv file")
paramMatchTag = flag.String("matchtag", "", "match data table file tags in v3 Index file")
v3GenList = []V3GenEntry{
{"gosrc", gosrc.Generate, paramGoOut},
{"jsontext", jsontext.Generate, paramJsonOut},
{"luasrc", luasrc.Generate, paramLuaOut},
{"cssrc", cssrc.Generate, paramCSharpOut},
{"binpak", binpak.Generate, paramBinaryOut},
}
)
func GenFile(globals *model.Globals) error {
for _, entry := range v3GenList {
if *entry.flagstr == "" {
continue
}
filename := *entry.flagstr
if data, err := entry.f(globals); err != nil {
return err
} else {
report.Log.Infof(" [%s] %s", entry.name, filename)
err = helper.WriteFile(filename, data)
if err != nil {
return err
}
}
}
return nil
}
func V3Entry() {
globals := model.NewGlobals()
globals.Version = Version
globals.IndexFile = *paramIndexFile
globals.PackageName = *paramPackageName
globals.CombineStructName = *paramCombineStructName
globals.GenBinary = *paramBinaryOut != ""
globals.MatchTag = *paramMatchTag
if globals.MatchTag != "" {
report.Log.Infof("MatchTag: %s", globals.MatchTag)
}
idxloader := helper.NewFileLoader(true)
idxloader.UseGBKCSV = *paramUseGBKCSV
globals.IndexGetter = idxloader
globals.UseGBKCSV = *paramUseGBKCSV
var err error
err = compiler.Compile(globals)
if err != nil {
goto Exit
}
report.Log.Debugln("Generate files...")
err = GenFile(globals)
if err != nil {
goto Exit
}
return
Exit:
report.Log.Errorln(err)
os.Exit(1)
}