Unified handling of printing versions of programs (--version). Setting version to 0.5

This commit is contained in:
Sascha L. Teichmann 2015-07-26 22:04:16 +02:00
parent f6b5f9ce97
commit 62a53dc26b
6 changed files with 44 additions and 3 deletions

View File

@ -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.")
}

View File

@ -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 {

View File

@ -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)

View File

@ -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 {

View File

@ -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)

17
common/version.go Normal file
View File

@ -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)
}