-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (33 loc) · 994 Bytes
/
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
package main
import (
"flag"
_ "github.com/pingcap/parser/test_driver"
"kit/internal/sql"
"os"
"strings"
)
func main() {
ddl := flag.String("ddl-file", "", "ddl file path")
//inputSQLFile := flag.String("sql-file", "", "sql file path")
templateFile := flag.String("repo-tpl", "", "repository template file")
entityDir := flag.String("entity-output", "", "entity struct output dir")
modelDir := flag.String("model-output", "", "model struct output dir")
repoDir := flag.String("repo-output", "", "repository file output dir")
flag.Parse()
if ddl != nil && len(*ddl) != 0 {
// init generator
gen := &sql.Generator{
FieldTypeMap: make(map[string]string),
OutputEntity: trimDirPath(entityDir),
OutputModel: trimDirPath(modelDir),
OutputRepo: trimDirPath(repoDir),
RepoTemplate: *templateFile,
DDLFile: *ddl,
}
// generate code
gen.Do()
}
}
func trimDirPath(path *string) string {
return strings.TrimRight(*path, string(os.PathSeparator))
}