Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
cd528e54
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cd528e54
编写于
9月 04, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
energy-command-line, 增加全自动安装energy整个开发环境
上级
11411c01
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
169 addition
and
5 deletion
+169
-5
cmd/internal/env/env.go
cmd/internal/env/env.go
+166
-2
cmd/internal/install/install.go
cmd/internal/install/install.go
+3
-3
未找到文件。
cmd/internal/env/env.go
浏览文件 @
cd528e54
...
...
@@ -11,6 +11,7 @@
package
env
import
(
"bytes"
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/tools"
...
...
@@ -54,7 +55,46 @@ func SetGoEnv(goRoot string) {
args
=
[]
string
{
"path"
,
"%path%;%GOROOT%
\\
bin"
}
cmd
.
Command
(
"setx"
,
args
...
)
}
else
{
//export GOROOT=/home/yanghy/app/go
//export GOCACHE=$GOROOT/go-build
//export GOBIN=$GOROOT/bin
//export PATH=$PATH:$GOBIN
//var exGoRoot = fmt.Sprintf("export GOROOT=%s", goRoot)
//var exGoCache = "export GOCACHE==$GOROOT/go-build"
//var exGoBin = "export GOBIN=$GOROOT/bin"
//var exPath = "export PATH=$PATH:$GOBIN"
//var envFiles []string
//if command.IsLinux {
// envFiles = []string{".profile", ".zshrc", ".bashrc"}
//} else if command.IsDarwin {
// envFiles = []string{".profile", ".zshrc", ".bash_profile"}
//}
//homeDir, err := homedir.Dir()
//if err != nil {
// println(err.Error())
// return
//}
//for _, file := range envFiles {
// var fp = path.Join(homeDir, file)
// cmd.Command("touch", fp)
// f, err := os.OpenFile(fp, os.O_RDWR|os.O_APPEND, 0666)
// if err == nil {
// var oldContent string
// if contentBytes, err := ioutil.ReadAll(f); err == nil {
// content := string(contentBytes)
// oldContent = content
// var lines = strings.Split(content, "\n")
// var exist = false
// for i := 0; i < len(lines); i++ {
// line := lines[i]
// if strings.Index(line, energyHomeKey) == 0 {
// content = strings.ReplaceAll(content, line, energyHome)
// exist = true
// }
// }
// }
// }
//}
}
println
(
"
\n
Hint: Reopen the cmd window for the Go command to take effect."
)
}
...
...
@@ -91,7 +131,11 @@ func SetEnergyHomeEnv(homePath string) {
}
else
if
command
.
IsDarwin
{
envFiles
=
[]
string
{
".profile"
,
".zshrc"
,
".bash_profile"
}
}
homeDir
,
_
:=
homedir
.
Dir
()
homeDir
,
err
:=
homedir
.
Dir
()
if
err
!=
nil
{
println
(
err
.
Error
())
return
}
for
_
,
file
:=
range
envFiles
{
var
fp
=
path
.
Join
(
homeDir
,
file
)
cmd
.
Command
(
"touch"
,
fp
)
...
...
@@ -133,6 +177,7 @@ func SetEnergyHomeEnv(homePath string) {
f
.
WriteString
(
"
\n
"
)
f
.
WriteString
(
energyHome
)
f
.
WriteString
(
"
\n
"
)
f
.
Close
()
}
}
else
{
f
.
Close
()
...
...
@@ -142,3 +187,122 @@ func SetEnergyHomeEnv(homePath string) {
}
println
(
"
\n
Hint: Reopen the cmd window to make the environment variables take effect."
)
}
func
setEnv
(
exs
[]
string
,
exGoBinPath
,
bin
string
)
{
cmd
:=
toolsCommand
.
NewCMD
()
cmd
.
MessageCallback
=
func
(
s
[]
byte
,
e
error
)
{
fmt
.
Println
(
"CMD:"
,
string
(
s
),
" error:"
,
e
)
}
defer
cmd
.
Close
()
var
envFiles
[]
string
if
command
.
IsLinux
{
envFiles
=
[]
string
{
".profile"
,
".zshrc"
,
".bashrc"
}
}
else
if
command
.
IsDarwin
{
envFiles
=
[]
string
{
".profile"
,
".zshrc"
,
".bash_profile"
}
}
homeDir
,
err
:=
homedir
.
Dir
()
// test
homeDir
=
"E:
\\
app"
envFiles
=
[]
string
{
".profile"
,
".zshrc"
,
".bashrc"
}
if
err
!=
nil
{
println
(
err
.
Error
())
return
}
var
isExport
=
func
(
line
string
)
(
string
,
bool
)
{
for
_
,
ex
:=
range
exs
{
exName
:=
strings
.
Split
(
ex
,
"="
)[
0
]
if
strings
.
Index
(
line
,
exName
)
==
0
{
return
ex
,
true
}
}
return
""
,
false
}
var
isExportPath
=
func
(
line
string
)
bool
{
if
strings
.
Index
(
line
,
"export PATH"
)
==
0
{
if
strings
.
Contains
(
line
,
bin
)
{
return
true
}
}
return
false
}
for
_
,
file
:=
range
envFiles
{
var
fp
=
path
.
Join
(
homeDir
,
file
)
cmd
.
Command
(
"touch"
,
fp
)
f
,
err
:=
os
.
OpenFile
(
fp
,
os
.
O_RDWR
|
os
.
O_APPEND
,
0666
)
if
err
==
nil
{
var
oldContent
string
if
contentBytes
,
err
:=
ioutil
.
ReadAll
(
f
);
err
==
nil
{
content
:=
string
(
contentBytes
)
oldContent
=
content
var
newContent
=
new
(
bytes
.
Buffer
)
var
lines
=
strings
.
Split
(
content
,
"
\n
"
)
var
exist
=
false
var
gobin
=
false
for
i
:=
0
;
i
<
len
(
lines
);
i
++
{
line
:=
strings
.
TrimSpace
(
lines
[
i
])
if
line
==
""
{
continue
}
if
exGoBinPath
!=
""
&&
isExportPath
(
line
)
{
//是path,并且有gobin
newContent
.
WriteString
(
exGoBinPath
)
gobin
=
true
}
else
{
// 其它变量, 判断是否存在,如果存在替换, 否则将原来的添加进来
if
ex
,
ok
:=
isExport
(
line
);
ok
{
newContent
.
WriteString
(
ex
)
exist
=
true
}
else
{
newContent
.
WriteString
(
line
)
}
}
newContent
.
WriteString
(
"
\n
"
)
}
if
exist
{
// 如果path里没有gobin, 添加一个
if
exGoBinPath
!=
""
&&
!
gobin
{
newContent
.
WriteString
(
exGoBinPath
)
newContent
.
WriteString
(
"
\n
"
)
}
// 有就覆盖掉之前的, 要先关闭掉文件
if
err
:=
f
.
Close
();
err
==
nil
{
// 如果关闭文件流成功, 重新写入覆盖文件
var
oldWrite
=
func
()
{
if
f
,
err
=
os
.
OpenFile
(
fp
,
os
.
O_RDWR
,
0666
);
err
==
nil
{
f
.
WriteString
(
oldContent
)
f
.
Close
()
}
}
// 打开覆盖模式
if
newOpenFile
,
err
:=
os
.
OpenFile
(
fp
,
os
.
O_RDWR
|
os
.
O_TRUNC
,
0666
);
err
==
nil
{
// 写入,如果失败,把老的写入
if
_
,
err
:=
newOpenFile
.
Write
(
newContent
.
Bytes
());
err
==
nil
{
newOpenFile
.
Close
()
}
else
{
newOpenFile
.
Close
()
oldWrite
()
}
}
else
{
oldWrite
()
}
}
}
else
{
// 都没有全添加一次
for
_
,
ex
:=
range
exs
{
f
.
WriteString
(
"
\n
"
)
f
.
WriteString
(
ex
)
f
.
WriteString
(
"
\n
"
)
}
// 如果path里没有gobin, 添加一个
if
exGoBinPath
!=
""
&&
!
gobin
{
f
.
WriteString
(
exGoBinPath
)
f
.
WriteString
(
"
\n
"
)
}
f
.
Close
()
}
}
else
{
f
.
Close
()
}
}
}
}
cmd/internal/install/install.go
浏览文件 @
cd528e54
...
...
@@ -97,8 +97,8 @@ func installGolang(c *command.Config) string {
version
:=
command
.
GolangDefaultVersion
gos
:=
runtime
.
GOOS
arch
:=
runtime
.
GOARCH
gos
=
"darwin"
arch
=
"amd64"
//
gos = "darwin"
//
arch = "amd64"
ext
:=
exts
[
gos
]
if
!
tools
.
IsExist
(
s
)
{
println
(
"Directory does not exist. Creating directory."
,
s
)
...
...
@@ -131,7 +131,7 @@ func installGolang(c *command.Config) string {
// 使用 go 名字做为 go 安装目录
targetPath
:=
filepath
.
Join
(
s
,
"go"
)
// 释放文件
if
!
command
.
IsWindows
{
if
command
.
IsWindows
{
//zip
ExtractUnZip
(
savePath
,
targetPath
)
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录