Skip to content

Commit 49c2dfa

Browse files
committed
cmd: add version.go
1 parent 20efe57 commit 49c2dfa

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.DS_Store
99

1010
/Godeps/_workspace
11+
/cmd/version.go
1112
.htaccess
1213

1314
/bin

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ export GO15VENDOREXPERIMENT=1
44

55
build-all: redis-port
66

7-
redis-port:
7+
build-deps:
8+
@mkdir -p bin && bash version
9+
10+
redis-port: build-deps
811
go build -i -o bin/redis-port ./cmd
912

1013
clean:

cmd/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"fmt"
78
"runtime"
89
"strconv"
910
"strings"
@@ -66,6 +67,7 @@ Usage:
6667
redis-port restore [--ncpu=N] [--parallel=M] [--input=INPUT] [--faketime=FAKETIME] [--extra] [--filterdb=DB] --target=TARGET [--auth=AUTH] [--redis|--codis]
6768
redis-port sync [--ncpu=N] [--parallel=M] --from=MASTER [--password=PASSWORD] [--psync] [--filterdb=DB] --target=TARGET [--auth=AUTH] [--redis|--codis] [--sockfile=FILE [--filesize=SIZE]]
6869
redis-port dump [--ncpu=N] [--parallel=M] --from=MASTER [--password=PASSWORD] [--extra] [--output=OUTPUT]
70+
redis-port --version
6971
7072
Options:
7173
-n N, --ncpu=N Set runtime.GOMAXPROCS to N.
@@ -90,6 +92,13 @@ Options:
9092
log.PanicError(err, "parse arguments failed")
9193
}
9294

95+
switch {
96+
case d["--version"].(bool):
97+
fmt.Println("version:", Version)
98+
fmt.Println("compile:", Compile)
99+
return
100+
}
101+
93102
if s, ok := d["--ncpu"].(string); ok && s != "" {
94103
n, err := parseInt(s, 1, 1024)
95104
if err != nil {

version

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
version=`git log --date=iso --pretty=format:"%cd @%H @" -1 && git describe --tag`
4+
if [ $? -ne 0 ]; then
5+
version="unknown version"
6+
fi
7+
8+
compile=`date +"%F %T %z"`" by "`go version`
9+
if [ $? -ne 0 ]; then
10+
compile="unknown datetime"
11+
fi
12+
13+
cat << EOF | gofmt > cmd/version.go
14+
package main
15+
16+
const (
17+
Version = "$version"
18+
Compile = "$compile"
19+
)
20+
EOF
21+
22+
cat << EOF > bin/version
23+
version = $version
24+
compile = $compile
25+
EOF

0 commit comments

Comments
 (0)