Skip to content

Commit

Permalink
cmd: add version.go
Browse files Browse the repository at this point in the history
  • Loading branch information
spinlock committed Feb 22, 2017
1 parent 20efe57 commit 49c2dfa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.DS_Store

/Godeps/_workspace
/cmd/version.go
.htaccess

/bin
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"fmt"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions version
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49c2dfa

Please sign in to comment.