增加golang版本获取

This commit is contained in:
白茶清欢 2023-04-09 22:44:37 +08:00
parent 908a0097d1
commit 4d4b871d4d
2 changed files with 18 additions and 4 deletions

5
git.go
View File

@ -231,6 +231,7 @@ func (g *git) Clone(repo string, saveDir string) *define.Result {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 22:15 2023/4/9 // Date : 22:15 2023/4/9
func (g *git) Version() *define.Result { func (g *git) Version() (string, error) {
return Execute(g.workDir, g.gitCmdPath, []string{"version"}) r := Execute(g.workDir, g.gitCmdPath, []string{"version"})
return string(r.Output), r.Error
} }

View File

@ -21,9 +21,12 @@ import (
// //
// Date : 20:04 2022/5/22 // Date : 20:04 2022/5/22
func Golang(workDir string, goCmdPath string) *golang { func Golang(workDir string, goCmdPath string) *golang {
if len(goCmdPath) == 0 {
goCmdPath, _ = Check("go")
if len(goCmdPath) == 0 { if len(goCmdPath) == 0 {
goCmdPath = "go" goCmdPath = "go"
} }
}
return &golang{ return &golang{
workDir: workDir, workDir: workDir,
goCmdPath: goCmdPath, goCmdPath: goCmdPath,
@ -146,7 +149,7 @@ func (g *golang) FormatCode() *define.Result {
// //
// Date : 19:25 2022/6/26 // Date : 19:25 2022/6/26
func (g *golang) GetGoENV() define.GoENV { func (g *golang) GetGoENV() define.GoENV {
result := Execute(g.workDir, "go", []string{"env"}) result := Execute(g.workDir, g.goCmdPath, []string{"env"})
return g.FormatGoENV(string(result.Output)) return g.FormatGoENV(string(result.Output))
} }
@ -194,3 +197,13 @@ func (g *golang) SwagInit(param []string) *define.Result {
swagCmdPath := envResult.GOPATH + "/bin/swag" swagCmdPath := envResult.GOPATH + "/bin/swag"
return Execute(g.workDir, swagCmdPath, param) return Execute(g.workDir, swagCmdPath, param)
} }
// Version 获取版本信息
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 22:42 2023/4/9
func (g *golang) Version() (string, error) {
result := Execute(g.workDir, g.goCmdPath, []string{"version"})
return string(result.Output), result.Error
}