-
Notifications
You must be signed in to change notification settings - Fork 49
/
cmd.go
106 lines (100 loc) · 2.32 KB
/
cmd.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
package cmd
import (
"fmt"
"github.com/LyricTian/gin-admin-cli/cmd/generate"
"github.com/LyricTian/gin-admin-cli/cmd/new"
"github.com/urfave/cli"
)
// NewCommand 创建项目命令
func NewCommand() cli.Command {
return cli.Command{
Name: "new",
Aliases: []string{"n"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "dir, d",
Usage: "项目生成目录",
},
&cli.StringFlag{
Name: "pkg, p",
Usage: "项目包名",
},
&cli.BoolFlag{
Name: "mirror, m",
Usage: "使用国内镜像(gitee.com)",
},
&cli.BoolFlag{
Name: "web, w",
Usage: "包含web项目",
},
},
Action: func(c *cli.Context) error {
cfg := new.Config{
Dir: c.String("dir"),
PkgName: c.String("pkg"),
UseMirror: c.Bool("mirror"),
IncludeWeb: c.Bool("web"),
}
return new.Exec(cfg)
},
}
}
// GenerateCommand 生成项目模块命令
func GenerateCommand() cli.Command {
return cli.Command{
Name: "generate",
Aliases: []string{"g"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "dir, d",
Usage: "项目生成目录",
Required: true,
},
&cli.StringFlag{
Name: "pkg, p",
Usage: "项目包名",
Required: true,
},
&cli.StringFlag{
Name: "name, n",
Usage: "模块名称(结构体名称)",
},
&cli.StringFlag{
Name: "comment, c",
Usage: "模块注释",
},
&cli.StringFlag{
Name: "file, f",
Usage: "指定模板文件(.json,模板配置可参考说明)",
},
&cli.StringFlag{
Name: "module, m",
Usage: "生成模块(以逗号分隔,支持:all,schema,entity,model,bll,ctl,api)",
},
},
Action: func(c *cli.Context) error {
cfg := generate.Config{
Dir: c.String("dir"),
PkgName: c.String("pkg"),
Name: c.String("name"),
Comment: c.String("comment"),
File: c.String("file"),
Modules: c.String("module"),
}
if cfg.Dir == "" {
fmt.Println("请指定项目目录")
return nil
} else if cfg.PkgName == "" {
fmt.Println("请指定包名")
return nil
} else if cfg.Name == "" && cfg.File == "" {
fmt.Println("请指定模块名称或模板文件")
return nil
} else if cfg.Name != "" && cfg.Comment == "" {
fmt.Println("请指定模块说明")
return nil
}
return generate.Exec(cfg)
},
}
}