mirror of
https://github.com/beego/bee.git
synced 2024-11-24 08:30:53 +00:00
80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
path "path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
)
|
|
|
|
var cmdVersion = &Command{
|
|
UsageLine: "version",
|
|
Short: "show the bee & beego version",
|
|
Long: `
|
|
show the bee & beego version
|
|
|
|
bee version
|
|
bee: 1.1.1
|
|
beego: 1.2
|
|
`,
|
|
}
|
|
|
|
func init() {
|
|
cmdVersion.Run = versionCmd
|
|
}
|
|
|
|
func versionCmd(cmd *Command, args []string) {
|
|
fmt.Println("bee :" + version)
|
|
fmt.Println("beego :" + getbeegoVersion())
|
|
fmt.Println("Go :" + runtime.Version())
|
|
}
|
|
|
|
func getbeegoVersion() string {
|
|
gopath := os.Getenv("GOPATH")
|
|
re, err := regexp.Compile(`const 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"
|
|
}
|