-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmake-model.go
52 lines (47 loc) · 1.48 KB
/
make-model.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
package main
import (
"go-api/cmd/util"
"go-api/core"
"go-api/global"
"go-api/initialize"
cmd "github.com/18211167516/go-cmd"
)
// versionCmd represents the version command
var makeCmd = &cmd.Command{
Use: "make:model",
Short: "读取表结构生成Model文件",
Long: `读取mysql的表结构转成Model文件`,
Example: `
读取表:tests 生成model:Test
默认生成到app/models下
./cmd.exe make:model -t=tests
生成到app/models/test下
./cmd.exe make:model -t=tests -f=test
`,
Run: func(Command *cmd.Command, args []string) {
table, _ := Command.Flags().GetString("table")
prefix, _ := Command.Flags().GetString("prefix")
file, _ := Command.Flags().GetString("file")
global.VP = core.Viper("../static/config/app.toml") //初始化配置
dsn := initialize.GetMasterDsn()
vip := core.Viper("./config/cmd.toml")
config := &util.T2tConfig{
StructNameRtrims: vip.GetBool("StructNameRtrims"),
UcFirstOnly: vip.GetBool("UcFirstOnly"),
SavePath: vip.GetString("SavePath"),
}
grom := util.NewTable2Struct(config)
grom.
Table(table).
Prefix(prefix).
SavePath(file).
Dsn(dsn).
Run()
},
}
func init() {
cmd.RootCmd.AddCommand(makeCmd)
makeCmd.Flags().StringP("table", "t", "", "指定的表名,如果未指定则全部导出")
makeCmd.Flags().StringP("prefix", "p", "", "表前缀")
makeCmd.Flags().StringP("file", "f", "", "生成的目录,默认是../app/models下的目录")
}