-
Notifications
You must be signed in to change notification settings - Fork 0
/
zelusctl.go
136 lines (131 loc) · 2.71 KB
/
zelusctl.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
136
package main
import (
"fmt"
"github.com/gozelus/zelus_rest/cli/actions"
"github.com/urfave/cli"
"os"
)
var apiCommand = cli.Command{
Name: "api",
Usage: "根据 api 生成代码",
Subcommands: []cli.Command{
{
Name: "application",
Usage: "根据 api 文件生成 go 项目代码",
Flags: []cli.Flag{
cli.StringFlag{
Required: true,
Name: "file",
Usage: `api 文件的入口`,
},
cli.StringFlag{
Required: true,
Name: "appname",
Usage: `工程名`,
},
},
Action: actions.GenApis,
},
{
Name: "code",
Usage: "生成各语言请求代码",
Subcommands: []cli.Command{
{
Name: "js",
Usage: "生成 js 请求代码",
Flags: []cli.Flag{
cli.StringFlag{
Required: true,
Name: "file",
Usage: `api 文件的入口`,
},
},
Action: actions.GenJsRequestCode,
},
{
Name: "go",
Usage: "生成 go 请求代码",
Flags: []cli.Flag{
cli.StringFlag{
Required: true,
Name: "file",
Usage: `api 文件的入口`,
},
},
},
},
},
},
}
var repoCommand = cli.Command{
Name: "repo",
Usage: "生成数据库模型 repo 代码",
Subcommands: []cli.Command{
{
Name: "mysql",
Usage: `根据 MySQL 表结构定义生成模型代码`,
Subcommands: []cli.Command{
{
Name: "datasource",
Usage: `根据 MySQL 连接串链接`,
Flags: []cli.Flag{
cli.StringFlag{
Required: true,
Name: "url",
Usage: `连接串, 如root:password@tcp(127.0.0.1:3306)/database`,
},
cli.StringFlag{
Required: true,
Name: "table, t",
Usage: `表名`,
},
},
Action: actions.GenRepo,
},
},
},
},
}
var modelCommand = cli.Command{
Name: "model",
Usage: "生成数据库模型代码",
Subcommands: []cli.Command{
{
Name: "mysql",
Usage: `根据 MySQL 表结构定义生成模型代码`,
Subcommands: []cli.Command{
{
Name: "datasource",
Usage: `根据 MySQL 连接串链接`,
Flags: []cli.Flag{
cli.StringFlag{
Required: true,
Name: "url",
Usage: `连接串, 如root:password@tcp(127.0.0.1:3306)/database`,
},
cli.StringFlag{
Required: true,
Name: "table, t",
Usage: `表名`,
},
},
Action: actions.GenModel,
},
},
},
},
}
var commands = []cli.Command{
apiCommand,
modelCommand,
repoCommand,
}
func main() {
app := cli.NewApp()
app.Usage = "a cli tool to generate code"
app.Commands = commands
// cli already print error messages
if err := app.Run(os.Args); err != nil {
fmt.Println("error:", err)
}
}