2 Star 1 Fork 2

go-mao/mao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
haitgo 提交于 2022-11-29 11:15 . v1.0.0
package main
import (
"fmt"
"os"
"strings"
)
func main() {
args := os.Args[1:]
argsLen := len(args)
if argsLen < 3 {
fmt.Println("请输入:mao 命令 参数... ")
fmt.Println(`
命令 new:
子命令:
app 创建一个web项目,例如:mao new app blog
mod 创建一个web模块,例如:mao new mod pay ;(注意执行命令所在的目录)
comop 创建一个web组件,例如:mao new comp user; (注意执行命令所在的目录)
`)
return
}
if args[0] == "new" {
action, name := args[1], args[2]
switch action {
case "app":
mod = name
copyDir("demo/app", name)
writeMod(name)
case "module", "mod":
copyDir("demo/app/modules/demo", name)
case "comp", "component":
copyDir("demo/app/modules/demo/components/user", name)
default:
fmt.Println("参数错误")
return
}
}
}
var mod string
// 获取当前应用的mod名称
func getModName() string {
if mod != "" {
return mod
}
workPath := getWorPath()
for index, item := range workPath {
if item == "modules" {
mod = workPath[index-1]
return mod
}
}
fmt.Println("请确认所在目录是否为web项目")
os.Exit(0)
return ""
}
func getWorPath() []string {
workDir, _ := os.Getwd()
workDir = strings.ReplaceAll(workDir, `\`, "/")
workDir = strings.TrimSuffix(workDir, "/")
return strings.Split(workDir, "/")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-mao/mao.git
git@gitee.com:go-mao/mao.git
go-mao
mao
mao
v1.0.15

搜索帮助