From fff001fd2e1613d86be9fccc41532eb8c5f5b076 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 20 Mar 2019 17:16:07 -0700 Subject: [PATCH] cmd/loopd: show version on start up, add new --version flag --- cmd/loopd/config.go | 11 ++++++----- cmd/loopd/main.go | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/loopd/config.go b/cmd/loopd/config.go index e37dcd9..53b82f1 100644 --- a/cmd/loopd/config.go +++ b/cmd/loopd/config.go @@ -9,11 +9,12 @@ type lndConfig struct { type viewParameters struct{} type config struct { - Insecure bool `long:"insecure" description:"disable tls"` - Network string `long:"network" description:"network to run on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"` - SwapServer string `long:"swapserver" description:"swap server address host:port"` - RPCListen string `long:"rpclisten" description:"Address to listen on for gRPC clients"` - RESTListen string `long:"restlisten" description:"Address to listen on for REST clients"` + ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"` + Insecure bool `long:"insecure" description:"disable tls"` + Network string `long:"network" description:"network to run on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"` + SwapServer string `long:"swapserver" description:"swap server address host:port"` + RPCListen string `long:"rpclisten" description:"Address to listen on for gRPC clients"` + RESTListen string `long:"restlisten" description:"Address to listen on for REST clients"` Lnd *lndConfig `group:"lnd" namespace:"lnd"` diff --git a/cmd/loopd/main.go b/cmd/loopd/main.go index 433c869..fd78fb8 100644 --- a/cmd/loopd/main.go +++ b/cmd/loopd/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "sync" flags "github.com/jessevdk/go-flags" @@ -72,6 +73,17 @@ func start() error { return err } + // Show the version and exit if the version flag was specified. + appName := filepath.Base(os.Args[0]) + appName = strings.TrimSuffix(appName, filepath.Ext(appName)) + if config.ShowVersion { + fmt.Println(appName, "version", loop.Version()) + os.Exit(0) + } + + // Print the version before executing either primary directive. + logger.Infof("Version: %v", loop.Version()) + // Execute command. if parser.Active == nil { return daemon(&config)