supporting --version

This commit is contained in:
Shlomi Noach 2016-05-17 11:51:21 +02:00
parent c6a371e6db
commit 41b0a4f317
2 changed files with 15 additions and 2 deletions

View File

@ -1,12 +1,14 @@
#!/bin/bash #!/bin/bash
# #
# #
RELEASE_VERSION="0.7.2"
buildpath=/tmp/gh-ost buildpath=/tmp/gh-ost
target=gh-ost target=gh-ost
timestamp=$(date "+%Y%m%d%H%M%S") timestamp=$(date "+%Y%m%d%H%M%S")
mkdir -p ${buildpath} 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 "Building OS/X binary"
echo "GO15VENDOREXPERIMENT=1 GOOS=darwin GOARCH=amd64 $gobuild" | bash echo "GO15VENDOREXPERIMENT=1 GOOS=darwin GOARCH=amd64 $gobuild" | bash

View File

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