-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
158 lines (130 loc) · 2.86 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
package main
import (
"embed"
"fmt"
"os"
"strings"
"github.com/liuxiaobopro/qsgo/global"
fmtp "github.com/liuxiaobopro/qsgo/log/fmt"
"github.com/liuxiaobopro/qsgo/service/web"
arrayx "github.com/liuxiaobopro/gobox/array"
stringx "github.com/liuxiaobopro/gobox/string"
)
var (
version string
debug = false
userHomePath string // 用户家目录
qsgoPath string
webTplPath string
projectWebTplPath = "tpl"
//go:embed VERSION
versionFile embed.FS
)
func init() {
//#region 初始化
//#region 通用
global.Debug = debug
global.Version = version
//#endregion
//#region 用户相关
u, err := os.UserHomeDir()
if err != nil {
panic(err)
}
fmtp.Println("home:", u)
global.UserHomePath, userHomePath = u, u
global.QsgoPath, qsgoPath = userHomePath+"/.qsgo", userHomePath+"/.qsgo"
global.WebTplPath, webTplPath = qsgoPath+"/tpl", qsgoPath+"/tpl"
//#endregion
//#region 项目相关
// 获取当前目录
pwd, err := os.Getwd()
if err != nil {
panic(err)
}
fmtp.Println("pwd:", pwd)
global.ProjectPath = pwd
//#endregion
//#endregion
//#region 获取当前目录下version文件的内容
versionByte, err := versionFile.ReadFile("VERSION")
if err != nil {
panic(err)
}
version = string(versionByte)
//#endregion
initTpl()
}
func main() {
args := os.Args[1:]
if len(args) == 0 {
help()
return
}
if len(args) == 2 {
if args[0] == "debug" {
debug = true
global.Debug = debug
}
}
var v string
if arrayx.IsIn(args, "debug") {
debug = true
global.Debug = debug
if len(args) <= 1 {
fmt.Println("debug不能单独使用")
return
}
v = args[1]
} else {
v = args[0]
}
fmtp.Println("args:", strings.Join(args, " "))
if stringx.Has(v, byte(':')) {
s := strings.Split(v, ":")
switch s[0] {
case "web":
web.Start(s[1])
}
} else {
switch v {
case "h":
case "help":
help()
default:
fmt.Println("参数错误")
}
}
}
func help() {
fmt.Println(`
_______ _______ _______ _______
( ___ )( ____ \( ____ \( ___ )
| ( ) || ( \/| ( \/| ( ) |
| | | || (_____ | | | | | |
| | | |(_____ )| | ____ | | | |
| | /\| | ) || | \_ )| | | |
| (_\ \ |/\____) || (___) || (___) |
(____\/_)\_______)(_______)(_______)
这是一个辅助完成Go项目的工具
Version: ` + version + `
用法:
qsgo [参数:功能=参数值]
参数:
---------------------------------------------------
h, help 显示帮助信息
qsgo
qsgo h
qsgo help
---------------------------------------------------
web 生成web项目
qsgo web:name=项目名 [生成项目]
- **必须安装git**
- 最好找个空目录执行
- 第一次执行可能会失败, 请再次执行
qsgo web:api=接口名 [生成接口]
- **必须在项目目录下执行**
qsgo web:router=方法名 [生成路由]
- **必须在项目目录下执行**
`)
}