Add version command

pull/20/head v1.6.2
rkfg 2 years ago
parent 9e2e01487f
commit f59d2466e5

@ -52,6 +52,7 @@ type configParams struct {
NodeCacheFilename string `long:"node-cache-filename" description:"save and load other nodes information to this file, improves cold start performance" json:"node_cache_filename" toml:"node_cache_filename"`
NodeCacheLifetime int `long:"node-cache-lifetime" description:"nodes with last update older than this time (in minutes) will be removed from cache after loading it" json:"node_cache_lifetime" toml:"node_cache_lifetime"`
NodeCacheInfo bool `long:"node-cache-info" description:"show red and cyan 'x' characters in routes to indicate node cache misses and hits respectively" json:"node_cache_info" toml:"node_cache_info"`
Version bool `short:"v" long:"version" description:"show program version and exit"`
}
var params, cfgParams configParams
@ -329,7 +330,10 @@ func tryRapidRebalance(ctx context.Context, r *regolancer, from, to uint64, rout
}
func preflightChecks(params *configParams) error {
if params.Version {
printVersion()
os.Exit(1)
}
if params.Connect == "" {
params.Connect = "127.0.0.1:10009"
}

@ -0,0 +1,28 @@
package main
import (
"fmt"
"os"
"runtime/debug"
)
func printVersion() {
info, ok := debug.ReadBuildInfo()
if !ok {
fmt.Printf("No build info available")
} else {
settings := map[string]string{}
for _, bs := range info.Settings {
settings[bs.Key] = bs.Value
}
version := info.Main.Version
if rev, ok := settings["vcs.revision"]; ok && version == "(devel)" {
version = "git" + rev[:8]
}
if settings["vcs.modified"] == "true" {
version += "-dirty"
}
fmt.Printf("Regolancer %s, built with %s\nSource: https://github.com/rkfg/regolancer\n", version, info.GoVersion)
}
os.Exit(1)
}
Loading…
Cancel
Save