-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·188 lines (182 loc) · 4.48 KB
/
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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
import (
"fmt"
"os"
"time"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "createproject"
app.Version = "0.1.0"
app.Compiled = time.Now()
app.Authors = []cli.Author{
cli.Author{
Name: "derek",
Email: "fghosth@163.com",
},
}
app.Copyright = "(c) derek fan"
app.Usage = "创建基于gokit的项目文件"
app.UsageText = "创建基于gokit的项目文件"
app.Commands = []cli.Command{
{
Name: "micser",
Aliases: []string{"ms"},
Usage: "根据service生成微服务项目文件",
Flags: []cli.Flag{
cli.StringFlag{
Name: "component, c",
Value: "all",
Usage: "要生成的组件,默认all.可选值:service,logging,proxying(TODO),transport,endpoint,instrumenting,util。多选请用分号分割 logging:proxying:endpoint",
},
cli.StringFlag{
Name: "file, f",
Value: "serviceI.go",
Usage: "指定接口文件,默认为",
},
cli.StringFlag{
Name: "cover",
Value: "false",
Usage: "是否覆盖已有文件,默认值false.可选值:true,false",
},
},
Action: func(c *cli.Context) error {
return CgokitFile(c)
},
},
{
Name: "test",
Aliases: []string{"t"},
Usage: "生成测试文件",
Flags: []cli.Flag{
cli.StringFlag{
Name: "DIR, d",
Value: "",
Usage: "需要生成测试文件的目录",
},
cli.StringFlag{
Name: "cover",
Value: "false",
Usage: "是否覆盖已有文件,默认值false.可选值:true,false",
},
},
Action: func(c *cli.Context) error {
return CTestFile(c)
},
},
{
Name: "createsql",
Aliases: []string{"cs"},
Usage: "根据struct生成sql脚本。支持mysql,mariadb,postgresql,cockroach",
Flags: []cli.Flag{
cli.StringFlag{
Name: "database, d",
Value: "mysql",
Usage: "需生成的数据库脚本.可选值:mysql,mariadb,postgresql,cockroach",
},
cli.StringFlag{
Name: "file, f",
Value: "",
Usage: "struct文件.",
},
cli.StringFlag{
Name: "cover",
Value: "false",
Usage: "是否覆盖已有文件,默认值false.可选值:true,false",
},
},
Action: func(c *cli.Context) error {
return CsqlFile(c)
},
},
{
Name: "MysqlToCockroach",
Aliases: []string{"m2c"},
Usage: "根据mysql脚本生成cockroachDB脚本。只支持create table和insert语句,用于数据迁移",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Value: "",
Usage: "struct文件.",
},
cli.StringFlag{
Name: "cover",
Value: "false",
Usage: "是否覆盖已有文件,默认值false.可选值:true,false",
},
},
Action: func(c *cli.Context) error {
return cockroachsqlFromMysql(c)
},
},
{
Name: "createmodel",
Aliases: []string{"cm"},
Usage: "根据struct生成model。包括基础的增删改查,并映射到struct。支持mysql,mariadb,postgresql,cockroach",
Flags: []cli.Flag{
cli.StringFlag{
Name: "location, l",
Value: "",
Usage: "当前包的名字如 【jvole.com/createProject/ormstruct/base】 就是『jvole.com/createProject/』",
},
cli.StringFlag{
Name: "file, f",
Value: "",
Usage: "struct文件.",
},
cli.StringFlag{
Name: "cover",
Value: "false",
Usage: "是否覆盖已有文件,默认值false.可选值:true,false",
},
},
Action: func(c *cli.Context) error {
return CmodelFile(c)
},
},
{
Name: "createstruct",
Aliases: []string{"cst"},
Usage: "根据数据库脚本生成struct。支持mysql,mariadb,postgresql,cockroach",
Flags: []cli.Flag{
cli.StringFlag{
Name: "database, d",
Value: "mysql",
Usage: "选择数据类型.可选值:mysql,mariadb,postgresql,cockroach",
},
cli.StringFlag{
Name: "file, f",
Value: "",
Usage: "sql文件.",
},
cli.StringFlag{
Name: "cover",
Value: "false",
Usage: "是否覆盖已有文件,默认值false.可选值:true,false",
},
},
Action: func(c *cli.Context) error {
return CstructFile(c)
},
},
{
Name: "init",
Aliases: []string{"init"},
Usage: "生成项目目录结构",
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Value: "./",
Usage: "sql文件.",
},
},
Action: func(c *cli.Context) error {
err := initProject(c)
fmt.Println(err)
return err
},
},
}
app.Run(os.Args)
}