mirror of
https://github.com/rkfg/regolancer
synced 2024-11-15 00:15:27 +00:00
Add version command
This commit is contained in:
parent
9e2e01487f
commit
f59d2466e5
6
main.go
6
main.go
@ -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"
|
||||
}
|
||||
|
28
version.go
Normal file
28
version.go
Normal file
@ -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…
Reference in New Issue
Block a user