mirror of
https://gitee.com/energye/energy.git
synced 2025-12-06 16:19:23 +08:00
U: Optimized CLI init commands and parameters
This commit is contained in:
@@ -45,6 +45,7 @@ const (
|
||||
IsAMD64 = runtime.GOARCH == "amd64"
|
||||
IsARM = runtime.GOARCH == "arm"
|
||||
IsARM64 = runtime.GOARCH == "arm64"
|
||||
IsLoong64 = runtime.GOARCH == "loong64"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
17
cmd/internal/env/env.go
vendored
17
cmd/internal/env/env.go
vendored
@@ -77,13 +77,16 @@ func Env(c *command.Config) error {
|
||||
case "registry":
|
||||
GlobalDevEnvConfig.Registry = val
|
||||
case "version":
|
||||
// 修复版本号
|
||||
if val[0] != 'v' {
|
||||
val = "v" + val
|
||||
}
|
||||
// 验证版本号格式
|
||||
if tools.VerifyRelease(val) {
|
||||
return errors.New("incorrect version format '" + val + "'. example: v1.0.0")
|
||||
if val != "" {
|
||||
// 修复版本号
|
||||
if val[0] != 'v' {
|
||||
val = "v" + val
|
||||
}
|
||||
// 验证版本号格式
|
||||
if !tools.VerifyRelease(val) {
|
||||
err := fmt.Sprintf("Incorrect version format '%v'. Example: v1.0.0", val)
|
||||
return errors.New(err)
|
||||
}
|
||||
}
|
||||
GlobalDevEnvConfig.Version = val
|
||||
}
|
||||
|
||||
@@ -50,17 +50,19 @@ func runInit(c *command.Config) error {
|
||||
}
|
||||
// 创建的项目名
|
||||
m.Name = strings.TrimSpace(m.Name)
|
||||
// 设置 go.mod 里使用的版本号
|
||||
if m.Version == "" {
|
||||
// 使用全局默认版本号
|
||||
// 尝试全局默认版本号
|
||||
m.Version = env.GlobalDevEnvConfig.Version
|
||||
}
|
||||
if m.Version == "" {
|
||||
// 使用从远程服务获取最新版本号
|
||||
// 尝试使用从远程服务获取最新版本号
|
||||
latestVersion, err := remotecfg.LatestVersion()
|
||||
err = errors.New("ttt")
|
||||
if err == nil {
|
||||
m.Version = fmt.Sprintf("v%v.%v.%v", latestVersion.Major, latestVersion.Minor, latestVersion.Build)
|
||||
} else {
|
||||
//获取失败, 要求输入版本号
|
||||
//最后获取失败, 要求输入版本号
|
||||
term.Logger.Error("Failed to retrieve version information from the remote service.")
|
||||
term.Logger.Error(err.Error())
|
||||
var inputVersion string
|
||||
@@ -71,33 +73,35 @@ func runInit(c *command.Config) error {
|
||||
}
|
||||
m.Version = inputVersion
|
||||
}
|
||||
// 修复版本号
|
||||
m.Version = strings.ToLower(m.Version)
|
||||
if m.Version[0] != 'v' {
|
||||
m.Version = "v" + m.Version
|
||||
}
|
||||
// 修复版本号
|
||||
m.Version = strings.ToLower(m.Version)
|
||||
if m.Version[0] != 'v' {
|
||||
m.Version = "v" + m.Version
|
||||
}
|
||||
// 验证版本号格式, vx.x.x
|
||||
if !tools.VerifyRelease(m.Version) {
|
||||
err := fmt.Sprintf("Incorrect version format '%v'. Example: v1.0.0", m.Version)
|
||||
return errors.New(err)
|
||||
}
|
||||
if m.ResLoad == "" || (m.ResLoad != "1" && m.ResLoad != "2") {
|
||||
options := []string{"HTTP", "Local Load"}
|
||||
printer := term.DefaultInteractiveSelect.WithOnInterruptFunc(func() {
|
||||
os.Exit(1)
|
||||
}).WithOptions(options)
|
||||
printer.CheckmarkANSI()
|
||||
printer.DefaultText = "Resource Loading. Default HTTP"
|
||||
printer.Filter = false
|
||||
selectedOption, err := printer.Show()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pterm.Info.Printfln("Selected: %s", pterm.Green(selectedOption))
|
||||
if selectedOption == "" || selectedOption == "HTTP" {
|
||||
m.ResLoad = "1"
|
||||
} else if selectedOption == "Local Load" {
|
||||
m.ResLoad = "2"
|
||||
}
|
||||
}
|
||||
// 验证版本号格式
|
||||
if tools.VerifyRelease(m.Version) {
|
||||
return errors.New("incorrect version format '" + m.Version + "'. example: v1.0.0")
|
||||
}
|
||||
|
||||
options := []string{"HTTP", "Local Load"}
|
||||
printer := term.DefaultInteractiveSelect.WithOnInterruptFunc(func() {
|
||||
os.Exit(1)
|
||||
}).WithOptions(options)
|
||||
printer.CheckmarkANSI()
|
||||
printer.DefaultText = "Resource Loading. Default HTTP"
|
||||
printer.Filter = false
|
||||
selectedOption, err := printer.Show()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pterm.Info.Printfln("Selected: %s", pterm.Green(selectedOption))
|
||||
if selectedOption == "" || selectedOption == "HTTP" {
|
||||
m.ResLoad = "1"
|
||||
} else if selectedOption == "Local Load" {
|
||||
m.ResLoad = "2"
|
||||
}
|
||||
|
||||
return initialize.InitEnergyProject(c)
|
||||
|
||||
@@ -73,7 +73,7 @@ func generaProject(c *command.Config) error {
|
||||
term.Logger.Info("Create Project", term.Logger.Args("Name", c.Init.Name))
|
||||
if tools.IsExist(projectPath) {
|
||||
term.Logger.Warn(fmt.Sprintf("Project dir `%s` exist, delete init default files.", c.Init.Name))
|
||||
var deleteFiles = []string{ /*"resources", */ "main.go", "go.mod", "go.sum", "resources/index.html", "README.md"}
|
||||
deleteFiles := []string{ /*"resources", */ "main.go", "go.mod", "go.sum", "resources/index.html", "README.md"}
|
||||
for _, fileName := range consts.EnergyProjectConfig {
|
||||
deleteFiles = append(deleteFiles, project.PlatformConfigFile(fileName))
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func generaProject(c *command.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if consts.IsLinux && consts.IsARM64 {
|
||||
if consts.IsLinux && (consts.IsARM64 || consts.IsLoong64) {
|
||||
if err := createFile("assets/initialize/run.sh", "run.sh", nil, 0755, "\r", ""); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func generaProject(c *command.Config) error {
|
||||
func checkEnv(init *command.Init) {
|
||||
term.Logger.Info("Check the current environment and follow the prompts if there are any")
|
||||
// 检查Go环境
|
||||
if !tools.CommandExists("go") {
|
||||
if env.GlobalDevEnvConfig.GoCMD() == "" {
|
||||
term.Logger.Warn("Golang development environment not installed, Download-URL: ", term.Logger.Args("Download-URL", "https://golang.google.cn/dl/", "ENERGY CLI", "energy install"))
|
||||
} else {
|
||||
var version string
|
||||
@@ -236,7 +236,7 @@ func checkEnv(init *command.Init) {
|
||||
}
|
||||
if consts.IsWindows {
|
||||
// 检查nsis
|
||||
if !tools.CommandExists("makensis") {
|
||||
if env.GlobalDevEnvConfig.NSISCMD() == "" {
|
||||
term.Logger.Warn(`NSIS not installed, Unable to create installation package through energy command line.`)
|
||||
} else {
|
||||
term.Logger.Info(`NSIS OK`)
|
||||
@@ -245,7 +245,7 @@ func checkEnv(init *command.Init) {
|
||||
}
|
||||
if !consts.IsDarwin {
|
||||
// 检查upx
|
||||
if !tools.CommandExists("upx") {
|
||||
if env.GlobalDevEnvConfig.UPXCMD() == "" {
|
||||
term.Logger.Warn(`UPX not installed`)
|
||||
} else {
|
||||
term.Logger.Info(`UPX OK`)
|
||||
@@ -257,10 +257,12 @@ func checkEnv(init *command.Init) {
|
||||
if !isCEF {
|
||||
term.Logger.Warn(`CEF Framework is not installed
|
||||
Installing using ENERGY CLI`, term.Logger.Args("ENERGY CLI", "energy install"))
|
||||
} else if !isLCL {
|
||||
}
|
||||
if !isLCL {
|
||||
term.Logger.Warn(`LibLCL is not installed
|
||||
Installing using ENERGY CLI`, term.Logger.Args("ENERGY CLI", "energy install"))
|
||||
} else {
|
||||
}
|
||||
if isCEF && isLCL {
|
||||
term.Logger.Info("CEF Framework OK")
|
||||
init.IEnv = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user