forked from GoAdminGroup/go-admin
/
cli.go
131 lines (106 loc) · 3.75 KB
/
cli.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
// Copyright 2019 GoAdmin Core Team. All rights reserved.
// Use of this source code is governed by a Apache-2.0 style
// license that can be found in the LICENSE file.
package main
import (
_ "github.com/davidlcarrascal/go-admin/modules/db/drivers/mysql"
_ "github.com/davidlcarrascal/go-admin/modules/db/drivers/postgres"
_ "github.com/davidlcarrascal/go-admin/modules/db/drivers/sqlite"
"fmt"
cli "github.com/jawher/mow.cli"
"github.com/mgutz/ansi"
"os"
"runtime"
"runtime/debug"
)
func main() {
var verbose *bool
defer func() {
if err := recover(); err != nil {
if errs, ok := err.(error); ok {
fmt.Println()
if runtime.GOOS == "windows" && errs.Error() == "Incorrect function." {
fmt.Println(ansi.Color("go-admin cli error: cli has not supported MINGW64 for now, please use cmd terminal instead.", "red"))
fmt.Println("know more here: http://forum.go-admin.cn/threads/2")
} else {
fmt.Println(ansi.Color("go-admin cli error: "+errs.Error(), "red"))
if *verbose {
fmt.Println(string(debug.Stack()))
}
}
fmt.Println()
}
}
}()
app := cli.App("adm", "GoAdmin cli tool for developing and generating")
app.Spec = "[-v]"
verbose = app.BoolOpt("v verbose", false, "debug info output")
// quiet
app.Command("-V version", "display this application version", func(cmd *cli.Cmd) {
cmd.Action = func() {
cliInfo()
}
})
app.Command("combine", "combine assets", func(cmd *cli.Cmd) {
cmd.Command("css", "combine css assets", func(cmd *cli.Cmd) {
var (
rootPath = cmd.StringOpt("s src", "./resource/assets/src/css/combine/", "css src path")
outputPath = cmd.StringOpt("d dist", "./resource/assets/dist/css/all.min.css", "css output path")
)
cmd.Action = func() {
cssMinifier(*rootPath, *outputPath)
}
})
cmd.Command("js", "combine js assets", func(cmd *cli.Cmd) {
var (
rootPath = cmd.StringOpt("s src", "./resource/assets/src/js/combine/", "js src path")
outputPath = cmd.StringOpt("d dist", "./resource/assets/dist/js/all.min.js", "js output path")
)
cmd.Action = func() {
jsMinifier(*rootPath, *outputPath)
}
})
})
app.Command("compile", "compile template files or assets to one go file", func(cmd *cli.Cmd) {
cmd.Command("tpl", "compile template files", func(cmd *cli.Cmd) {
var (
rootPath = cmd.StringOpt("s src", "./resource/pages/", "template files src path")
outputPath = cmd.StringOpt("d dist", "./template.go", "compile file output path")
packageName = cmd.StringOpt("p package", "newTmplTheme", "the package name")
)
cmd.Action = func() {
compileTmpl(*rootPath, *outputPath, *packageName)
}
})
cmd.Command("asset", "compile assets", func(cmd *cli.Cmd) {
var (
rootPath = cmd.StringOpt("s src", "./resource/assets/dist/", "assets root path")
outputPath = cmd.StringOpt("d dist", "./resource/", "compile file output path")
packageName = cmd.StringOpt("p package", "resource", "package name of the output golang file")
)
cmd.Action = func() {
compileAsset(*rootPath, *outputPath, *packageName)
}
})
})
app.Command("develop", "commands for developing", func(cmd *cli.Cmd) {
cmd.Command("tpl", "generate a theme project from a remote template", func(cmd *cli.Cmd) {
var (
moduleName = cmd.StringOpt("m module", "github.com/GoAdminGroup/themes/newTmpl", "the module name of your theme")
themeName = cmd.StringOpt("n name", "newTmplTheme", "the name of your theme")
)
cmd.Action = func() {
getThemeTemplate(*moduleName, *themeName)
}
})
})
app.Command("generate", "generate table model files", func(cmd *cli.Cmd) {
var (
config = cmd.StringOpt("c config", "", "config ini path")
)
cmd.Action = func() {
generating(*config)
}
})
_ = app.Run(os.Args)
}