提交 7674c729 编写于 作者: yanghye's avatar yanghye

energy-command-line, 优化命令 install .

上级 a94ad940
......@@ -62,7 +62,7 @@ func main() {
fmt.Fprintf(os.Stderr, "%s\n%s", command.UsageLine, command.Long)
os.Exit(1)
}
fmt.Println("Energy executing:", command.Short)
fmt.Println(command.Short)
if err := command.Run(cc); err != nil {
fmt.Fprint(os.Stderr, err.Error()+"\n")
os.Exit(1)
......
......@@ -34,6 +34,10 @@ type Install struct {
Download string `short:"d" long:"download" description:"Download Source, 0:gitee or 1:github, Default empty" default:""`
All string `short:"a" long:"all" description:"Install all, skip installation prompts (Y/n), default empty:n" default:""`
CEF string `short:"c" long:"cef" description:"Install system supports CEF version, provide 4 options, default empty. default, windows7, gtk2, flash" default:""`
IGolang bool
ICEF bool
INSIS bool
IUPX bool
}
type Package struct {
......
......@@ -17,7 +17,7 @@ import (
var CmdInstall = &command.Command{
UsageLine: "install -p [path] -v [version] -n [name] -d [download] -a [all] -c [cef]",
Short: "Automatically configure the CEF and Energy framework",
Short: "Automatic installation and configuration of the energy framework complete development environment",
Long: `
-p Installation directory Default current directory
-v Specifying a version number,Default latest.\
......@@ -31,7 +31,7 @@ var CmdInstall = &command.Command{
87 : CEF 87.1.14 is the last one to support Flash.
. Execute default command
Automatically install and configure the Energy development environment.
Automatic installation and configuration of the energy framework complete development environment.
Installation package is downloaded over the network during the installation process.
According to the prompt (Y), install Golang、CEF(Chromium Embedded Framework)、NSIS, If installed, skip.
`,
......
......@@ -25,6 +25,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
)
......@@ -42,6 +43,7 @@ type downloadInfo struct {
func Install(c *command.Config) {
// 初始配置和安装目录
initInstall(c)
willInstall := checkInstallEnv(c)
var (
goRoot string
goSuccessCallback func()
......@@ -50,6 +52,15 @@ func Install(c *command.Config) {
nsisRoot string
nsisSuccessCallback func()
)
if len(willInstall) > 0 {
println("Following will be installed")
for _, name := range willInstall {
println("\t", name)
}
println("Press Enter to start installation")
var s string
fmt.Scanln(&s)
}
// 安装Go开发环境
goRoot, goSuccessCallback = installGolang(c)
// 安装CEF二进制框架
......@@ -70,6 +81,7 @@ func Install(c *command.Config) {
if cefFrameworkRoot != "" {
env.SetEnergyHomeEnv(cefFrameworkRoot)
}
println("-----------------------------------------------------")
// success 输出
if nsisSuccessCallback != nil {
nsisSuccessCallback()
......@@ -80,6 +92,17 @@ func Install(c *command.Config) {
if cefFrameworkSuccessCallback != nil {
cefFrameworkSuccessCallback()
}
// end
//if len(willInstall) > 0 {
// print("was installed: ")
// for i, name := range willInstall {
// if i > 0 {
// print("|")
// }
// print(name)
// }
// println()
//}
}
func cefInstallPathName(c *command.Config) string {
......@@ -94,6 +117,59 @@ func nsisInstallPathName(c *command.Config) string {
return filepath.Join(c.Install.Path, "nsis")
}
func checkInstallEnv(c *command.Config) (result []string) {
skip := strings.ToLower(c.Install.All) == "y"
var check = func(chkInstall func() bool, name string, yes func()) {
if chkInstall() {
println(" ", name, "installed")
} else {
fmt.Printf(" %s: Not installed, install %s ? (Y/n): ", name, name)
var s string
if !skip {
fmt.Scanln(&s) // 跳过输入Y,
} else {
s = "y"
}
if strings.ToLower(s) == "y" {
result = append(result, name)
yes()
} else {
println(" ", name, "install skip")
}
}
}
// go
check(func() bool {
return tools.CommandExists("go")
}, "Golang", func() {
c.Install.IGolang = true
})
// nsis
check(func() bool {
if consts.IsWindows && runtime.GOARCH == "amd64" {
return tools.CommandExists("makensis")
} else {
println(" Non Windows amd64 skipping NSIS")
return false
}
}, "NSIS", func() {
c.Install.INSIS = true
})
// cef
check(func() bool {
return tools.CheckCEFDir()
}, "CEF Framework", func() {
c.Install.ICEF = true
})
// upx
check(func() bool {
return tools.CommandExists("upx")
}, "UPX", func() {
c.Install.IUPX = true
})
return
}
func initInstall(c *command.Config) {
if c.Install.Path == "" {
// current dir
......
......@@ -26,19 +26,9 @@ import (
)
func installCEFFramework(c *command.Config) (string, func()) {
if tools.CheckCEFDir() {
println("CEF Framework installed")
if !c.Install.ICEF {
return "", nil
}
print("CEF Framework is not installed. Determine whether to install CEF Framework? Y/n: ")
var s string
if strings.ToLower(c.Install.All) != "y" {
fmt.Scanln(&s)
if strings.ToLower(s) != "y" {
println("CEF Framework install exit")
return "", nil
}
}
// 获取提取文件配置
extractData, err := tools.HttpRequestGET(consts.DownloadExtractURL)
if err != nil {
......@@ -246,7 +236,7 @@ func installCEFFramework(c *command.Config) (string, func()) {
}
}
return installPathName, func() {
println("\nCEF Installed Successfully \nInstalled version:", c.Install.Version, liblclVersion)
println("\nCEF Installed Successfully Version:", c.Install.Version, liblclVersion)
if liblclModule == nil {
println("hint: liblcl module", liblclModuleName, `is not configured in the current version, You need to use built-in binary build. [go build -tags="tempdll"]`)
}
......
......@@ -19,25 +19,14 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
)
// 下载go并配置安装
func installGolang(c *command.Config) (string, func()) {
if tools.CommandExists("go") {
println("Golang installed")
if !c.Install.IGolang {
return "", nil
}
print("Golang not installed, do you want to install Golang? Y/n: ")
var s string
if strings.ToLower(c.Install.All) != "y" {
fmt.Scanln(&s)
if strings.ToLower(s) != "y" {
println("Golang install exit")
return "", nil
}
}
s = c.Install.Path // 安装目录
s := c.Install.Path // 安装目录
exts := map[string]string{
"darwin": "tar.gz",
"linux": "tar.gz",
......@@ -87,7 +76,7 @@ func installGolang(c *command.Config) (string, func()) {
ExtractUnTar(savePath, targetPath)
}
return targetPath, func() {
println("Golang Installed Successfully \nInstalled version:", version)
println("Golang Installed Successfully Version:", version)
}
}
return "", nil
......
......@@ -17,27 +17,15 @@ import (
"github.com/energye/energy/v2/cmd/internal/tools"
"path/filepath"
"runtime"
"strings"
)
func installNSIS(c *command.Config) (string, func()) {
if !c.Install.INSIS {
return "", nil
}
if consts.IsWindows && runtime.GOARCH == "amd64" {
if tools.CommandExists("makensis") {
//if tools.IsExist(filepath.Join(os.Getenv(consts.NSISHomeKey), "makensis.exe")) {
println("NSIS installed")
return "", nil
}
print("NSIS is not installed. Do you want to install NSIS? Y/n: ")
var s string
if strings.ToLower(c.Install.All) != "y" {
fmt.Scanln(&s)
if strings.ToLower(s) != "y" {
println("NSIS install exit")
return "", nil
}
}
// 下载并安装配置NSIS
s = c.Install.Path // 安装目录
s := c.Install.Path // 安装目录
version := consts.NSISDownloadVersion
fileName := fmt.Sprintf("nsis.windows.386-%s.zip", version)
downloadUrl := fmt.Sprintf(consts.NSISDownloadURL, fileName)
......@@ -66,11 +54,9 @@ func installNSIS(c *command.Config) (string, func()) {
//zip
ExtractUnZip(savePath, targetPath, true)
return targetPath, func() {
println("NSIS Installed Successfully \nInstalled version:", version)
println("NSIS Installed Successfully Version:", version)
}
}
} else {
println("Non Windows amd64 skipping nsis")
}
return "", nil
}
......@@ -49,7 +49,7 @@ func NewBar(totalVale int) *Bar {
totalValue: totalVale,
currentValue: 0,
progressGraphTotal: defaultCount,
progressGraph: "",
progressGraph: "=",
backGraph: " ",
progressEnds: Ends{Start: "[", End: "]"},
isShowPercent: true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册