-
Notifications
You must be signed in to change notification settings - Fork 3
/
mctl.go
135 lines (130 loc) · 3.26 KB
/
mctl.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"fmt"
"os"
"runtime"
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/tools/goctl/tpl"
"github.com/urfave/cli"
model "github.com/wenj91/mctl/command"
)
var (
BuildVersion = "1.0.0"
commands = []cli.Command{
{
Name: "model",
Usage: "generate model code",
Subcommands: []cli.Command{
{
Name: "mysql",
Usage: `generate mysql model`,
Subcommands: []cli.Command{
{
Name: "ddl",
Usage: `generate mysql model from ddl`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "src, s",
Usage: "the path or path globbing patterns of the ddl",
},
cli.StringFlag{
Name: "dir, d",
Usage: "the target dir",
},
cli.StringFlag{
Name: "style",
Usage: "the file naming format, see [https://github.com/tal-tech/go-zero/tree/master/tools/goctl/config/readme.md]",
},
cli.BoolFlag{
Name: "idea",
Usage: "for idea plugin [optional]",
},
},
Action: model.MysqlDDL,
},
{
Name: "datasource",
Usage: `generate model from datasource`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "url",
Usage: `the data source of database,like "root:password@tcp(127.0.0.1:3306)/database`,
},
cli.StringFlag{
Name: "table, t",
Usage: `the table or table globbing patterns in the database`,
},
cli.StringFlag{
Name: "dir, d",
Usage: "the target dir",
},
cli.StringFlag{
Name: "style",
Usage: "the file naming format, see [https://github.com/tal-tech/go-zero/tree/master/tools/goctl/config/readme.md]",
},
cli.BoolFlag{
Name: "idea",
Usage: "for idea plugin [optional]",
},
},
Action: model.MyDataSource,
},
},
},
},
},
{
Name: "template",
Usage: "template operation",
Subcommands: []cli.Command{
{
Name: "init",
Usage: "initialize the all templates(force update)",
Action: tpl.GenTemplates,
},
{
Name: "clean",
Usage: "clean the all cache templates",
Action: tpl.CleanTemplates,
},
{
Name: "update",
Usage: "update template of the target category to the latest",
Flags: []cli.Flag{
cli.StringFlag{
Name: "category,c",
Usage: "the category of template, enum [api,rpc,model,docker,kube]",
},
},
Action: tpl.UpdateTemplates,
},
{
Name: "revert",
Usage: "revert the target template to the latest",
Flags: []cli.Flag{
cli.StringFlag{
Name: "category,c",
Usage: "the category of template, enum [api,rpc,model,docker,kube]",
},
cli.StringFlag{
Name: "name,n",
Usage: "the target file name of template",
},
},
Action: tpl.RevertTemplates,
},
},
},
}
)
func main() {
logx.Disable()
app := cli.NewApp()
app.Usage = "a cli tool to generate code"
app.Version = fmt.Sprintf("%s %s/%s", BuildVersion, runtime.GOOS, runtime.GOARCH)
app.Commands = commands
// cli already print error messages
if err := app.Run(os.Args); err != nil {
fmt.Println("error:", err)
}
}