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

Tweaked the Bee banner

This commit is contained in:
Faissal Elamraoui 2016-07-31 23:23:07 +02:00
parent ea2376e90d
commit 7662cfe5d9
2 changed files with 32 additions and 28 deletions

View File

@ -21,11 +21,12 @@ type vars struct {
BeegoVersion string BeegoVersion string
} }
// Now returns the current local time in the specified layout
func Now(layout string) string { func Now(layout string) string {
return time.Now().Format(layout) return time.Now().Format(layout)
} }
// Init load the banner and prints it to output // InitBanner loads the banner and prints it to output
// All errors are ignored, the application will not // All errors are ignored, the application will not
// print the banner in case of error. // print the banner in case of error.
func InitBanner(out io.Writer, in io.Reader) { func InitBanner(out io.Writer, in io.Reader) {
@ -55,7 +56,7 @@ func show(out io.Writer, content string) {
os.Exit(2) os.Exit(2)
} }
t.Execute(out, vars{ err = t.Execute(out, vars{
runtime.Version(), runtime.Version(),
runtime.GOOS, runtime.GOOS,
runtime.GOARCH, runtime.GOARCH,
@ -66,4 +67,7 @@ func show(out io.Writer, content string) {
version, version,
getBeegoVersion(), getBeegoVersion(),
}) })
if err != nil {
panic(err)
}
} }

View File

@ -2,54 +2,47 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"io" "io"
"os" "os"
path "path/filepath" path "path/filepath"
"regexp" "regexp"
"bytes"
) )
var cmdVersion = &Command{ var cmdVersion = &Command{
UsageLine: "version", UsageLine: "version",
Short: "show the Bee, Beego and Go version", Short: "prints the current Bee version",
Long: ` Long: `
show the Bee, Beego and Go version Prints the current Bee, Beego and Go version alongside the platform information
bee version
bee :1.2.3
beego :1.4.2
Go :go version go1.3.3 linux/amd64
`, `,
} }
const verboseVersionBanner = const verboseVersionBanner string = `%s%s______
`______
| ___ \ | ___ \
| |_/ / ___ ___ | |_/ / ___ ___
| ___ \ / _ \ / _ \ | ___ \ / _ \ / _ \
| |_/ /| __/| __/ | |_/ /| __/| __/
\____/ \___| \___| v{{ .BeeVersion }} \____/ \___| \___| v{{ .BeeVersion }}%s
%s%s
Beego : {{ .BeegoVersion }} Beego : {{ .BeegoVersion }}
GoVersion : {{ .GoVersion }} GoVersion : {{ .GoVersion }}
GOOS : {{ .GOOS }} GOOS : {{ .GOOS }}
GOARCH : {{ .GOARCH }} GOARCH : {{ .GOARCH }}
NumCPU : {{ .NumCPU }} NumCPU : {{ .NumCPU }}
GOPATH : {{ .GOPATH }} GOPATH : {{ .GOPATH }}
GOROOT : {{ .GOROOT }} GOROOT : {{ .GOROOT }}
Compiler : {{ .Compiler }} Compiler : {{ .Compiler }}
Date : {{ Now "Monday, 2 Jan 2006" }} Date : {{ Now "Monday, 2 Jan 2006" }}%s
` `
const shortVersionBanner = const shortVersionBanner = `%s%s______
`______
| ___ \ | ___ \
| |_/ / ___ ___ | |_/ / ___ ___
| ___ \ / _ \ / _ \ | ___ \ / _ \ / _ \
| |_/ /| __/| __/ | |_/ /| __/| __/
\____/ \___| \___| v{{ .BeeVersion }} \____/ \___| \___| v{{ .BeeVersion }}%s
` `
func init() { func init() {
@ -61,12 +54,19 @@ func versionCmd(cmd *Command, args []string) int {
return 0 return 0
} }
// ShowVerboseVersionBanner prints the verbose version banner
func ShowVerboseVersionBanner() { func ShowVerboseVersionBanner() {
InitBanner(os.Stdout, bytes.NewBufferString(verboseVersionBanner)) w := NewColorWriter(os.Stdout)
coloredBanner := fmt.Sprintf(verboseVersionBanner, "\x1b[35m", "\x1b[1m", "\x1b[0m",
"\x1b[32m", "\x1b[1m", "\x1b[0m")
InitBanner(w, bytes.NewBufferString(coloredBanner))
} }
// ShowShortVersionBanner prints the short version banner
func ShowShortVersionBanner() { func ShowShortVersionBanner() {
InitBanner(os.Stdout, bytes.NewBufferString(shortVersionBanner)) w := NewColorWriter(os.Stdout)
coloredBanner := fmt.Sprintf(shortVersionBanner, "\x1b[35m", "\x1b[1m", "\x1b[0m")
InitBanner(w, bytes.NewBufferString(coloredBanner))
} }
func getBeegoVersion() string { func getBeegoVersion() string {