-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
88 lines (80 loc) · 1.72 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"os/exec"
path "path/filepath"
"regexp"
)
var cmdVersion = &Command{
UsageLine: "version",
Short: "show the Bee, Beego and Go version",
Long: `
show the Bee, Beego and Go version
bee version
bee :1.2.3
beego :1.4.2
Go :go version go1.3.3 linux/amd64
`,
}
func init() {
cmdVersion.Run = versionCmd
}
func versionCmd(cmd *Command, args []string) int {
fmt.Println("bee :" + version)
fmt.Println("beego :" + getbeegoVersion())
//fmt.Println("Go :" + runtime.Version())
goversion, err := exec.Command("go", "version").Output()
if err != nil {
log.Fatal(err)
}
fmt.Println("Go :" + string(goversion))
return 0
}
func getbeegoVersion() string {
gopath := os.Getenv("GOPATH")
re, err := regexp.Compile(`VERSION = "([0-9.]+)"`)
if err != nil {
return ""
}
if gopath == "" {
err = fmt.Errorf("you should set GOPATH in the env")
return ""
}
wgopath := path.SplitList(gopath)
for _, wg := range wgopath {
wg, _ = path.EvalSymlinks(path.Join(wg, "src", "github.com", "astaxie", "beego"))
filename := path.Join(wg, "beego.go")
_, err := os.Stat(filename)
if err != nil {
if os.IsNotExist(err) {
continue
}
ColorLog("[ERRO] get beego.go has error\n")
}
fd, err := os.Open(filename)
if err != nil {
ColorLog("[ERRO] open beego.go has error\n")
continue
}
reader := bufio.NewReader(fd)
for {
byteLine, _, er := reader.ReadLine()
if er != nil && er != io.EOF {
return ""
}
if er == io.EOF {
break
}
line := string(byteLine)
s := re.FindStringSubmatch(line)
if len(s) >= 2 {
return s[1]
}
}
}
return "you don't install beego,install first: github.com/astaxie/beego"
}