1
0
mirror of https://github.com/beego/bee.git synced 2024-11-14 17:00:54 +00:00
bee/version.go

89 lines
1.7 KiB
Go
Raw Normal View History

2014-05-16 17:37:45 +00:00
package main
import (
2014-05-22 02:35:37 +00:00
"bufio"
2014-05-16 17:37:45 +00:00
"fmt"
2014-05-22 02:35:37 +00:00
"io"
2014-08-11 00:57:20 +00:00
"log"
2014-05-22 02:35:37 +00:00
"os"
2014-08-11 00:57:20 +00:00
"os/exec"
2014-05-22 02:35:37 +00:00
path "path/filepath"
"regexp"
2014-05-16 17:37:45 +00:00
)
var cmdVersion = &Command{
UsageLine: "version",
Short: "show the Bee, Beego and Go version",
2014-05-16 17:37:45 +00:00
Long: `
show the Bee, Beego and Go version
2014-05-16 17:37:45 +00:00
bee version
bee :1.2.3
beego :1.4.2
Go :go version go1.3.3 linux/amd64
2014-05-16 17:37:45 +00:00
`,
}
func init() {
cmdVersion.Run = versionCmd
}
2014-08-15 09:38:51 +00:00
func versionCmd(cmd *Command, args []string) int {
2014-05-16 17:53:42 +00:00
fmt.Println("bee :" + version)
2014-05-22 02:35:37 +00:00
fmt.Println("beego :" + getbeegoVersion())
2014-08-11 00:57:20 +00:00
//fmt.Println("Go :" + runtime.Version())
goversion, err := exec.Command("go", "version").Output()
if err != nil {
log.Fatal(err)
}
fmt.Println("Go :" + string(goversion))
2014-08-15 09:38:51 +00:00
return 0
2014-05-22 02:35:37 +00:00
}
func getbeegoVersion() string {
gopath := os.Getenv("GOPATH")
re, err := regexp.Compile(`const VERSION = "([0-9.]+)"`)
2014-05-16 17:53:42 +00:00
if err != nil {
2014-05-22 02:35:37 +00:00
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]
}
}
2014-05-16 17:53:42 +00:00
}
2014-05-22 02:35:37 +00:00
return "you don't install beego,install first: github.com/astaxie/beego"
2014-05-16 17:37:45 +00:00
}