Merge pull request #35 from github/app-version

supporting --version
This commit is contained in:
Shlomi Noach 2016-05-17 11:51:55 +02:00
commit 9a3c607665
2 changed files with 15 additions and 2 deletions

View File

@ -1,12 +1,14 @@
#!/bin/bash
#
#
RELEASE_VERSION="0.7.2"
buildpath=/tmp/gh-ost
target=gh-ost
timestamp=$(date "+%Y%m%d%H%M%S")
mkdir -p ${buildpath}
gobuild="go build -o $buildpath/$target go/cmd/gh-ost/main.go"
ldflags="-X main.AppVersion=${RELEASE_VERSION}"
gobuild="go build -ldflags \"$ldflags\" -o $buildpath/$target go/cmd/gh-ost/main.go"
echo "Building OS/X binary"
echo "GO15VENDOREXPERIMENT=1 GOOS=darwin GOARCH=amd64 $gobuild" | bash

View File

@ -15,6 +15,8 @@ import (
"github.com/outbrain/golib/log"
)
var AppVersion string
// main is the application's entry point. It will either spawn a CLI or HTTP itnerfaces.
func main() {
migrationContext := base.GetMigrationContext()
@ -57,6 +59,7 @@ func main() {
debug := flag.Bool("debug", false, "debug mode (very verbose)")
stack := flag.Bool("stack", false, "add stack trace upon error")
help := flag.Bool("help", false, "Display usage")
version := flag.Bool("version", false, "Print version & exit")
flag.Parse()
if *help {
@ -64,6 +67,14 @@ func main() {
flag.PrintDefaults()
return
}
if *version {
appVersion := AppVersion
if appVersion == "" {
appVersion = "unversioned"
}
fmt.Println(appVersion)
return
}
log.SetLevel(log.ERROR)
if *verbose {
@ -106,7 +117,7 @@ func main() {
log.Fatale(err)
}
log.Info("starting gh-ost")
log.Info("starting gh-ost %+v", AppVersion)
migrator := logic.NewMigrator()
err := migrator.Migrate()