From 62a53dc26b8c1a6a043552c6f910348f38d69606 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 26 Jul 2015 22:04:16 +0200 Subject: [PATCH] Unified handling of printing versions of programs (--version). Setting version to 0.5 --- cmd/mtdbconverter/main.go | 6 ++++++ cmd/mtredisalize/main.go | 6 +++--- cmd/mtseeder/main.go | 6 ++++++ cmd/mttilemapper/main.go | 6 ++++++ cmd/mtwebmapper/main.go | 6 ++++++ common/version.go | 17 +++++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 common/version.go diff --git a/cmd/mtdbconverter/main.go b/cmd/mtdbconverter/main.go index 19c39e0..3aba021 100644 --- a/cmd/mtdbconverter/main.go +++ b/cmd/mtdbconverter/main.go @@ -98,6 +98,7 @@ func main() { dstBackend string srcInterleaved bool dstInterleaved bool + version bool ) flag.Usage = usage @@ -118,9 +119,14 @@ func main() { "Should dest database be interleaved?") flag.BoolVar(&dstInterleaved, "di", true, "Should source database be interleaved? Shorthand") + flag.BoolVar(&version, "version", false, "Print version and exit.") flag.Parse() + if version { + common.PrintVersionAndExit() + } + if flag.NArg() < 2 { log.Fatal("Missing source and/or destination database.") } diff --git a/cmd/mtredisalize/main.go b/cmd/mtredisalize/main.go index 98cbbd7..48086f9 100644 --- a/cmd/mtredisalize/main.go +++ b/cmd/mtredisalize/main.go @@ -13,11 +13,12 @@ import ( "os/signal" "runtime" "time" + + "bitbucket.org/s_l_teichmann/mtsatellite/common" ) const ( defaultMaxBulkStringSize = 32 * 1024 * 1024 - Version = "0.3" GCDuration = "24h" ChangeDuration = "30s" ) @@ -63,8 +64,7 @@ func main() { flag.Parse() if version { - fmt.Printf("Version: %s\n", Version) - os.Exit(0) + common.PrintVersionAndExit() } if flag.NArg() < 1 { diff --git a/cmd/mtseeder/main.go b/cmd/mtseeder/main.go index f32cbb6..dd85fee 100644 --- a/cmd/mtseeder/main.go +++ b/cmd/mtseeder/main.go @@ -25,6 +25,7 @@ func main() { skipPyramid bool transparent bool transparentDim float64 + version bool ) flag.IntVar(&port, "port", 6379, "port to of mtredisalize server") @@ -51,9 +52,14 @@ func main() { flag.Float64Var(&transparentDim, "td", common.DefaultTransparentDim*100.0, "Extra fimming of transparent nodes each depth meter in percent. (shorthand)") + flag.BoolVar(&version, "version", false, "Print version and exit.") flag.Parse() + if version { + common.PrintVersionAndExit() + } + if !skipBaseLevel { td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0) address := fmt.Sprintf("%s:%d", host, port) diff --git a/cmd/mttilemapper/main.go b/cmd/mttilemapper/main.go index 601466c..e1a4d83 100644 --- a/cmd/mttilemapper/main.go +++ b/cmd/mttilemapper/main.go @@ -28,6 +28,7 @@ func main() { transparent bool cpuProfile string transparentDim float64 + version bool ) flag.IntVar(&port, "port", 6379, "port to of mtredisalize server") @@ -51,9 +52,14 @@ func main() { &transparentDim, "transparent-dim", common.DefaultTransparentDim*100, "Extra dimming of transparent nodes every depth meter in percent (0-100).") flag.StringVar(&cpuProfile, "cpuprofile", "", "write cpu profile to file") + flag.BoolVar(&version, "version", false, "Print version and exit.") flag.Parse() + if version { + common.PrintVersionAndExit() + } + if cpuProfile != "" { f, err := os.Create(cpuProfile) if err != nil { diff --git a/cmd/mtwebmapper/main.go b/cmd/mtwebmapper/main.go index b368402..3f70e03 100644 --- a/cmd/mtwebmapper/main.go +++ b/cmd/mtwebmapper/main.go @@ -31,6 +31,7 @@ func main() { updateHosts string websockets bool playersFIFO string + version bool ) flag.IntVar(&webPort, "web-port", 8808, "port of the web server") flag.IntVar(&webPort, "p", 8808, "port of the web server (shorthand)") @@ -63,9 +64,14 @@ func main() { flag.BoolVar(&websockets, "ws", false, "Forward tile changes to clients via websockets (shorthand).") flag.StringVar(&playersFIFO, "players", "", "Path to FIFO file to read active players from.") flag.StringVar(&playersFIFO, "ps", "", "Path to FIFO file to read active players from (shorthand).") + flag.BoolVar(&version, "version", false, "Print version and exit.") flag.Parse() + if version { + common.PrintVersionAndExit() + } + router := mux.NewRouter() subBaseLine := newSubBaseLine(mapDir) diff --git a/common/version.go b/common/version.go new file mode 100644 index 0000000..215e70e --- /dev/null +++ b/common/version.go @@ -0,0 +1,17 @@ +// Copyright 2014 by Sascha L. Teichmann +// Use of this source code is governed by the MIT license +// that can be found in the LICENSE file. + +package common + +import ( + "fmt" + "os" +) + +const MTSatelliteVersion = "0.5" + +func PrintVersionAndExit() { + fmt.Printf("Version: %s\n", MTSatelliteVersion) + os.Exit(0) +}