2014-05-16 17:37:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-05-22 02:35:37 +00:00
|
|
|
"bufio"
|
2016-07-11 10:35:35 +00:00
|
|
|
"bytes"
|
2014-05-16 17:37:45 +00:00
|
|
|
"fmt"
|
2014-05-22 02:35:37 +00:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
path "path/filepath"
|
|
|
|
"regexp"
|
2014-05-16 17:37:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var cmdVersion = &Command{
|
|
|
|
UsageLine: "version",
|
2014-12-18 16:19:34 +00:00
|
|
|
Short: "show the Bee, Beego and Go version",
|
2014-05-16 17:37:45 +00:00
|
|
|
Long: `
|
2014-12-18 16:19:34 +00:00
|
|
|
show the Bee, Beego and Go version
|
2014-05-16 17:37:45 +00:00
|
|
|
|
|
|
|
bee version
|
2014-12-18 16:19:34 +00:00
|
|
|
bee :1.2.3
|
|
|
|
beego :1.4.2
|
|
|
|
Go :go version go1.3.3 linux/amd64
|
|
|
|
|
2014-05-16 17:37:45 +00:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
2016-07-11 10:35:35 +00:00
|
|
|
const verboseVersionBanner = `______
|
2016-06-01 12:30:29 +00:00
|
|
|
| ___ \
|
|
|
|
| |_/ / ___ ___
|
|
|
|
| ___ \ / _ \ / _ \
|
|
|
|
| |_/ /| __/| __/
|
|
|
|
\____/ \___| \___| v{{ .BeeVersion }}
|
|
|
|
|
|
|
|
Beego : {{ .BeegoVersion }}
|
|
|
|
GoVersion : {{ .GoVersion }}
|
|
|
|
GOOS : {{ .GOOS }}
|
|
|
|
GOARCH : {{ .GOARCH }}
|
|
|
|
NumCPU : {{ .NumCPU }}
|
|
|
|
GOPATH : {{ .GOPATH }}
|
|
|
|
GOROOT : {{ .GOROOT }}
|
|
|
|
Compiler : {{ .Compiler }}
|
|
|
|
Date : {{ Now "Monday, 2 Jan 2006" }}
|
|
|
|
`
|
|
|
|
|
2016-07-11 10:35:35 +00:00
|
|
|
const shortVersionBanner = `______
|
2016-06-01 12:30:29 +00:00
|
|
|
| ___ \
|
|
|
|
| |_/ / ___ ___
|
|
|
|
| ___ \ / _ \ / _ \
|
|
|
|
| |_/ /| __/| __/
|
|
|
|
\____/ \___| \___| v{{ .BeeVersion }}
|
|
|
|
`
|
|
|
|
|
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 {
|
2016-06-01 12:30:29 +00:00
|
|
|
ShowVerboseVersionBanner()
|
2014-08-15 09:38:51 +00:00
|
|
|
return 0
|
2014-05-22 02:35:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 12:30:29 +00:00
|
|
|
func ShowVerboseVersionBanner() {
|
|
|
|
InitBanner(os.Stdout, bytes.NewBufferString(verboseVersionBanner))
|
|
|
|
}
|
|
|
|
|
|
|
|
func ShowShortVersionBanner() {
|
|
|
|
InitBanner(os.Stdout, bytes.NewBufferString(shortVersionBanner))
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBeegoVersion() string {
|
2014-05-22 02:35:37 +00:00
|
|
|
gopath := os.Getenv("GOPATH")
|
2016-01-18 02:27:17 +00:00
|
|
|
re, err := regexp.Compile(`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 == "" {
|
2016-06-01 12:30:29 +00:00
|
|
|
err = fmt.Errorf("You should set GOPATH env variable")
|
2014-05-22 02:35:37 +00:00
|
|
|
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
|
|
|
|
}
|
2016-06-01 12:30:29 +00:00
|
|
|
ColorLog("[ERRO] Get `beego.go` has error\n")
|
2014-05-22 02:35:37 +00:00
|
|
|
}
|
|
|
|
fd, err := os.Open(filename)
|
|
|
|
if err != nil {
|
2016-06-01 12:30:29 +00:00
|
|
|
ColorLog("[ERRO] Open `beego.go` has error\n")
|
2014-05-22 02:35:37 +00:00
|
|
|
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
|
|
|
}
|
2016-06-01 12:30:29 +00:00
|
|
|
return "Beego not installed. Please install it first: https://github.com/astaxie/beego"
|
2014-05-16 17:37:45 +00:00
|
|
|
}
|