From 7662cfe5d9be231c3a463bba66fa8d38178917b8 Mon Sep 17 00:00:00 2001 From: Faissal Elamraoui Date: Sun, 31 Jul 2016 23:23:07 +0200 Subject: [PATCH] Tweaked the Bee banner --- banner.go | 8 ++++++-- version.go | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/banner.go b/banner.go index d04293b..af33ef3 100644 --- a/banner.go +++ b/banner.go @@ -21,11 +21,12 @@ type vars struct { BeegoVersion string } +// Now returns the current local time in the specified layout func Now(layout string) string { 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 // print the banner in case of error. func InitBanner(out io.Writer, in io.Reader) { @@ -55,7 +56,7 @@ func show(out io.Writer, content string) { os.Exit(2) } - t.Execute(out, vars{ + err = t.Execute(out, vars{ runtime.Version(), runtime.GOOS, runtime.GOARCH, @@ -66,4 +67,7 @@ func show(out io.Writer, content string) { version, getBeegoVersion(), }) + if err != nil { + panic(err) + } } diff --git a/version.go b/version.go index 43931e1..d9442aa 100644 --- a/version.go +++ b/version.go @@ -2,54 +2,47 @@ package main import ( "bufio" + "bytes" "fmt" "io" "os" path "path/filepath" "regexp" - "bytes" ) var cmdVersion = &Command{ UsageLine: "version", - Short: "show the Bee, Beego and Go version", + Short: "prints the current Bee version", Long: ` -show the Bee, Beego and Go version - -bee version - bee :1.2.3 - beego :1.4.2 - Go :go version go1.3.3 linux/amd64 +Prints the current Bee, Beego and Go version alongside the platform information `, } -const verboseVersionBanner = -`______ +const verboseVersionBanner string = `%s%s______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v{{ .BeeVersion }} - -Beego : {{ .BeegoVersion }} -GoVersion : {{ .GoVersion }} -GOOS : {{ .GOOS }} -GOARCH : {{ .GOARCH }} -NumCPU : {{ .NumCPU }} -GOPATH : {{ .GOPATH }} -GOROOT : {{ .GOROOT }} -Compiler : {{ .Compiler }} -Date : {{ Now "Monday, 2 Jan 2006" }} +\____/ \___| \___| v{{ .BeeVersion }}%s +%s%s +├── Beego : {{ .BeegoVersion }} +├── GoVersion : {{ .GoVersion }} +├── GOOS : {{ .GOOS }} +├── GOARCH : {{ .GOARCH }} +├── NumCPU : {{ .NumCPU }} +├── GOPATH : {{ .GOPATH }} +├── GOROOT : {{ .GOROOT }} +├── Compiler : {{ .Compiler }} +└── Date : {{ Now "Monday, 2 Jan 2006" }}%s ` -const shortVersionBanner = -`______ +const shortVersionBanner = `%s%s______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ -\____/ \___| \___| v{{ .BeeVersion }} +\____/ \___| \___| v{{ .BeeVersion }}%s ` func init() { @@ -61,12 +54,19 @@ func versionCmd(cmd *Command, args []string) int { return 0 } +// ShowVerboseVersionBanner prints the verbose version banner 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() { - 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 {