forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_v3.go
105 lines (80 loc) · 1.92 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
105
package main
import (
"flag"
"github.com/davyxu/tabtoy/v3/compiler"
"github.com/davyxu/tabtoy/v3/gen"
"github.com/davyxu/tabtoy/v3/gen/gosrc"
"github.com/davyxu/tabtoy/v3/gen/jsondata"
"github.com/davyxu/tabtoy/v3/helper"
"github.com/davyxu/tabtoy/v3/model"
"github.com/davyxu/tabtoy/v3/report"
"os"
)
type V3GenEntry struct {
f gen.GenFunc
name *string
}
// v3新增
var (
paramBuiltinSymbolFile = flag.Bool("builtinsymbol", false, "builtin symbols visible in table types")
paramIndexFile = flag.String("index", "", "input multi-files configs")
v3GenList = []V3GenEntry{
{gosrc.Generate, paramGoOut},
{jsondata.Generate, paramJsonOut},
}
)
func selectFileLoader(globals *model.Globals, para bool) {
globals.IndexGetter = new(helper.SyncFileLoader)
globals.Para = para
if globals.Para {
// 缓冲文件
asyncLoader := helper.NewAsyncFileLoader()
for _, pragma := range globals.IndexList {
asyncLoader.AddFile(pragma.TableFileName)
}
asyncLoader.Commit()
globals.TableGetter = asyncLoader
} else {
globals.TableGetter = globals.IndexGetter
}
}
func GenFile(globals *model.Globals) error {
for _, entry := range v3GenList {
if *entry.name == "" {
continue
}
filename := *entry.name
if data, err := entry.f(globals); err != nil {
return err
} else {
report.Log.Infoln(filename)
err = helper.WriteFile(filename, data)
if err != nil {
return err
}
}
}
return nil
}
func V3Entry() {
globals := model.NewGlobals()
globals.Version = Version_v3
model.BuiltinSymbolsVisible = *paramBuiltinSymbolFile
globals.IndexFile = *paramIndexFile
globals.PackageName = *paramPackageName
globals.CombineStructName = *paramCombineStructName
selectFileLoader(globals, *paramPara)
var err error
err = compiler.Compile(globals)
if err != nil {
goto Exit
}
err = GenFile(globals)
if err != nil {
goto Exit
}
return
Exit:
report.Log.Errorln(err)
os.Exit(1)
}