代码拉取完成,页面将自动刷新
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, "/")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。