From 96a444a56230a8db5fc408fcfe80f28ccf5338ca Mon Sep 17 00:00:00 2001 From: Liqueur Librazy Date: Sat, 29 Oct 2016 08:44:29 +0800 Subject: [PATCH] bin: add flag to print version information (#1896) --- tidb-server/main.go | 5 +++++ util/printer/printer.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/tidb-server/main.go b/tidb-server/main.go index 04e83790900b2..09128c3afb562 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -44,6 +44,7 @@ import ( ) var ( + version = flag.Bool("v", false, "print version information and exit") store = flag.String("store", "goleveldb", "registered store name, [memory, goleveldb, boltdb, tikv]") storePath = flag.String("path", "/tmp/tidb", "tidb storage path") logLevel = flag.String("L", "info", "log level: info, debug, warn, error, fatal") @@ -69,6 +70,10 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() + if *version { + printer.PrintRawTiDBInfo() + os.Exit(0) + } leaseDuration := parseLease() tidb.SetSchemaLease(leaseDuration) diff --git a/util/printer/printer.go b/util/printer/printer.go index b39ea8b6e4f46..8fb0bba6f2aa1 100644 --- a/util/printer/printer.go +++ b/util/printer/printer.go @@ -15,6 +15,7 @@ package printer import ( "bytes" + "fmt" "github.com/ngaut/log" ) @@ -33,6 +34,12 @@ func PrintTiDBInfo() { log.Infof("UTC Build Time: %s", TiDBBuildTS) } +// PrintRawTiDBInfo prints the TiDB version information without log info. +func PrintRawTiDBInfo() { + fmt.Println("Git Commit Hash:", TiDBGitHash) + fmt.Println("UTC Build Time: ", TiDBBuildTS) +} + // checkValidity checks whether cols and every data have the same length. func checkValidity(cols []string, datas [][]string) bool { colLen := len(cols)