-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtools.go
65 lines (53 loc) · 1.46 KB
/
gtools.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
package gtools
import (
"fmt"
"os/exec"
"github.com/xxjwxc/public/mylog"
"github.com/hjd919/gormt/data/dlg"
"github.com/hjd919/gormt/data/view/model"
"github.com/hjd919/gormt/data/config"
"github.com/hjd919/gormt/data/view/model/genmysql"
"github.com/hjd919/gormt/data/view/model/gensqlite"
"github.com/xxjwxc/public/tools"
)
// Execute exe the cmd
func Execute() {
if config.GetIsGUI() {
dlg.WinMain()
} else {
showCmd()
}
}
func showCmd() {
// var tt oauth_db.UserInfoTbl
// tt.Nickname = "ticket_001"
// orm.Where("nickname = ?", "ticket_001").Find(&tt)
// fmt.Println(tt)
var modeldb model.IModel
switch config.GetDbInfo().Type {
case 0:
modeldb = genmysql.GetModel()
case 1:
modeldb = gensqlite.GetModel()
}
if modeldb == nil {
mylog.Error(fmt.Errorf("modeldb not fund : please check db_info.type (0:mysql , 1:sqlite , 2:mssql) "))
return
}
pkg := modeldb.GenModel()
// gencnf.GenOutPut(&pkg)
// just for test
// out, _ := json.Marshal(pkg)
// tools.WriteFile("test.txt", []string{string(out)}, true)
list, _ := model.Generate(pkg)
for _, v := range list {
path := config.GetOutDir() + "/" + v.FileName
tools.WriteFile(path, []string{v.FileCtx}, true)
mylog.Info("formatting differs from goimport's:")
cmd, _ := exec.Command("goimports", "-l", "-w", path).Output()
mylog.Info(string(cmd))
mylog.Info("formatting differs from gofmt's:")
cmd, _ = exec.Command("gofmt", "-l", "-w", path).Output()
mylog.Info(string(cmd))
}
}