1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 05:00:54 +00:00

update bee get beego & go version

This commit is contained in:
astaxie 2014-05-22 10:35:37 +08:00
parent a6f9c78aaa
commit 94c9dee22c

View File

@ -1,11 +1,13 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"log" "io"
"os/exec" "os"
path "path/filepath"
"github.com/astaxie/beego" "regexp"
"runtime"
) )
var cmdVersion = &Command{ var cmdVersion = &Command{
@ -26,10 +28,52 @@ func init() {
func versionCmd(cmd *Command, args []string) { func versionCmd(cmd *Command, args []string) {
fmt.Println("bee :" + version) fmt.Println("bee :" + version)
fmt.Println("beego :" + beego.VERSION) fmt.Println("beego :" + getbeegoVersion())
goversion, err := exec.Command("go", "version").Output() fmt.Println("Go :" + runtime.Version())
}
func getbeegoVersion() string {
gopath := os.Getenv("GOPATH")
re, err := regexp.Compile(`const VERSION = "([0-9.]+)"`)
if err != nil { if err != nil {
log.Fatal(err) return ""
} }
fmt.Println("Go :" + string(goversion)) 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"
} }