From 49c2dfae85231934938e2e3bb713f0d0adf95864 Mon Sep 17 00:00:00 2001 From: spinlock Date: Wed, 22 Feb 2017 12:02:11 +0800 Subject: [PATCH] cmd: add version.go --- .gitignore | 1 + Makefile | 5 ++++- cmd/main.go | 9 +++++++++ version | 25 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 version diff --git a/.gitignore b/.gitignore index 2b34102..f012bda 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ .DS_Store /Godeps/_workspace +/cmd/version.go .htaccess /bin diff --git a/Makefile b/Makefile index 21a2dda..7a00862 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,10 @@ export GO15VENDOREXPERIMENT=1 build-all: redis-port -redis-port: +build-deps: + @mkdir -p bin && bash version + +redis-port: build-deps go build -i -o bin/redis-port ./cmd clean: diff --git a/cmd/main.go b/cmd/main.go index a9d6d5f..8e646df 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ package main import ( + "fmt" "runtime" "strconv" "strings" @@ -66,6 +67,7 @@ Usage: redis-port restore [--ncpu=N] [--parallel=M] [--input=INPUT] [--faketime=FAKETIME] [--extra] [--filterdb=DB] --target=TARGET [--auth=AUTH] [--redis|--codis] redis-port sync [--ncpu=N] [--parallel=M] --from=MASTER [--password=PASSWORD] [--psync] [--filterdb=DB] --target=TARGET [--auth=AUTH] [--redis|--codis] [--sockfile=FILE [--filesize=SIZE]] redis-port dump [--ncpu=N] [--parallel=M] --from=MASTER [--password=PASSWORD] [--extra] [--output=OUTPUT] + redis-port --version Options: -n N, --ncpu=N Set runtime.GOMAXPROCS to N. @@ -90,6 +92,13 @@ Options: log.PanicError(err, "parse arguments failed") } + switch { + case d["--version"].(bool): + fmt.Println("version:", Version) + fmt.Println("compile:", Compile) + return + } + if s, ok := d["--ncpu"].(string); ok && s != "" { n, err := parseInt(s, 1, 1024) if err != nil { diff --git a/version b/version new file mode 100755 index 0000000..ac0b379 --- /dev/null +++ b/version @@ -0,0 +1,25 @@ +#!/bin/bash + +version=`git log --date=iso --pretty=format:"%cd @%H @" -1 && git describe --tag` +if [ $? -ne 0 ]; then + version="unknown version" +fi + +compile=`date +"%F %T %z"`" by "`go version` +if [ $? -ne 0 ]; then + compile="unknown datetime" +fi + +cat << EOF | gofmt > cmd/version.go +package main + +const ( + Version = "$version" + Compile = "$compile" +) +EOF + +cat << EOF > bin/version +version = $version +compile = $compile +EOF