Skip to content

Commit 41b0a4f

Browse files
author
Shlomi Noach
committed
supporting --version
1 parent c6a371e commit 41b0a4f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/bin/bash
22
#
33
#
4+
RELEASE_VERSION="0.7.2"
45

56
buildpath=/tmp/gh-ost
67
target=gh-ost
78
timestamp=$(date "+%Y%m%d%H%M%S")
89
mkdir -p ${buildpath}
9-
gobuild="go build -o $buildpath/$target go/cmd/gh-ost/main.go"
10+
ldflags="-X main.AppVersion=${RELEASE_VERSION}"
11+
gobuild="go build -ldflags \"$ldflags\" -o $buildpath/$target go/cmd/gh-ost/main.go"
1012

1113
echo "Building OS/X binary"
1214
echo "GO15VENDOREXPERIMENT=1 GOOS=darwin GOARCH=amd64 $gobuild" | bash

go/cmd/gh-ost/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/outbrain/golib/log"
1616
)
1717

18+
var AppVersion string
19+
1820
// main is the application's entry point. It will either spawn a CLI or HTTP itnerfaces.
1921
func main() {
2022
migrationContext := base.GetMigrationContext()
@@ -57,13 +59,22 @@ func main() {
5759
debug := flag.Bool("debug", false, "debug mode (very verbose)")
5860
stack := flag.Bool("stack", false, "add stack trace upon error")
5961
help := flag.Bool("help", false, "Display usage")
62+
version := flag.Bool("version", false, "Print version & exit")
6063
flag.Parse()
6164

6265
if *help {
6366
fmt.Fprintf(os.Stderr, "Usage of gh-ost:\n")
6467
flag.PrintDefaults()
6568
return
6669
}
70+
if *version {
71+
appVersion := AppVersion
72+
if appVersion == "" {
73+
appVersion = "unversioned"
74+
}
75+
fmt.Println(appVersion)
76+
return
77+
}
6778

6879
log.SetLevel(log.ERROR)
6980
if *verbose {
@@ -106,7 +117,7 @@ func main() {
106117
log.Fatale(err)
107118
}
108119

109-
log.Info("starting gh-ost")
120+
log.Info("starting gh-ost %+v", AppVersion)
110121

111122
migrator := logic.NewMigrator()
112123
err := migrator.Migrate()

0 commit comments

Comments
 (0)