/
root.go
189 lines (180 loc) · 4.51 KB
/
root.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
189
package command
import (
"os"
"github.com/teamlint/ardan/cli/setting"
"github.com/teamlint/ardan/version"
"github.com/urfave/cli/v2"
)
var (
opts setting.Options
)
// Run command run
func Run() error {
app := &cli.App{
Name: "ardan",
Authors: []*cli.Author{&cli.Author{Name: "venjiang", Email: "venjiang@gmail.com"}},
Copyright: "Copyright teamlint.com",
Usage: "make an app bootstrap",
Version: version.Version,
Flags: flags(),
BashComplete: bashComplete,
Before: before,
After: after,
Action: func(c *cli.Context) error {
cli.ShowAppHelp(c)
// cli.ShowSubcommandHelp(c)
return nil
},
Commands: []*cli.Command{
Init,
Sync,
Gen,
NewCmd,
},
}
return app.Run(os.Args)
}
func flags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "tmpl",
Aliases: []string{"t"},
Value: "temp",
Usage: "template root dir",
Destination: &opts.TmplDir,
},
&cli.StringFlag{
Name: "conf",
Aliases: []string{"f"},
Value: "",
Usage: "config file path",
Destination: &opts.Config,
},
&cli.StringFlag{
Name: "db-driver",
Aliases: []string{"dd"},
Value: "postgres",
Usage: "database driver name: mysql|postgres",
Destination: &opts.DBDriver,
},
&cli.StringFlag{
Name: "db-name",
Aliases: []string{"dn"},
Value: "Ardan",
Usage: "database name",
Destination: &opts.DBName,
},
&cli.StringFlag{
Name: "db-conn",
Aliases: []string{"dc"},
Usage: "database connection string\n\t\te.g. postgres://postgres:123456@127.0.0.1:5432/ardan?sslmode=disable",
Destination: &opts.DBConnStr,
},
&cli.StringFlag{
Name: "mod",
Aliases: []string{"m"},
Usage: "go module name",
Required: false,
Destination: &opts.GoModName,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Value: ".",
Usage: "output directory",
Destination: &opts.OutputDir,
},
&cli.BoolFlag{
Name: "sample",
Aliases: []string{"s"},
Value: false,
Usage: "initial sample code",
Destination: &opts.Sample,
},
// project layout
&cli.StringFlag{
Name: "cmd",
Value: "cmd",
Usage: "[Layout] executed command root directory",
Destination: &opts.CmdDir,
},
&cli.StringFlag{
Name: "doc",
Value: "doc",
Usage: "[Layout] documents root directory",
Destination: &opts.DocDir,
},
&cli.StringFlag{
Name: "app",
Value: "app",
Usage: "[Layout] application layer root directory",
Destination: &opts.AppDir,
},
&cli.StringFlag{
Name: "model",
Value: "model",
Usage: "[Layout] application layer domain directory",
Destination: &opts.ModelDir,
},
&cli.StringFlag{
Name: "service",
Value: "service",
Usage: "[Layout] application layer service directory",
Destination: &opts.ServiceDir,
},
&cli.StringFlag{
Name: "repository",
Value: "repository",
Usage: "[Layout] application layer repository directory",
Destination: &opts.RepositoryDir,
},
&cli.StringFlag{
Name: "server",
Value: "server",
Usage: "[Layout] server layer root directory",
Destination: &opts.ServerDir,
},
&cli.StringFlag{
Name: "module",
Value: "module",
Usage: "[Layout] server layer module directory",
Destination: &opts.ServerModuleDir,
},
&cli.StringFlag{
Name: "global",
Value: "global",
Usage: "[Layout] server layer global directory",
Destination: &opts.ServerGlobalDir,
},
&cli.StringFlag{
Name: "controller",
Value: "controller",
Usage: "[Layout] server layer controller directory",
Destination: &opts.ControllerDir,
},
&cli.StringFlag{
Name: "middleware",
Value: "middleware",
Usage: "[Layout] server layer middleware directory",
Destination: &opts.MiddlewareDir,
},
&cli.StringFlag{
Name: "handler",
Value: "handler",
Usage: "[Layout] server layer handler directory",
Destination: &opts.HandlerDir,
},
}
}
func bashComplete(c *cli.Context) {
// fmt.Fprintf(c.App.Writer, "bashComplete\n")
}
func before(c *cli.Context) error {
// fmt.Fprintf(c.App.Writer, "before\n")
var err error
err = Setup(c)
return err
}
func after(c *cli.Context) error {
return nil
}