From 77fbfe6ea94d2b5fbd052ed0810c20bdfce39842 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Mon, 28 Sep 2020 11:18:15 -0700 Subject: [PATCH] add option for extended version (#16) --- Makefile | 4 ++++ cmd/aterm/appdialogs/version.go | 8 +++++++- cmd/aterm/climain.go | 3 ++- cmd/aterm/config/cli_parser.go | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ab9ee3e..7a2222d 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,10 @@ run-version: run-reset-hard: go run $(LD_FLAGS) cmd/aterm/*.go -reset-hard +.PHONY: run-help +run-help: + go run $(LD_FLAGS) cmd/aterm/*.go -h + .PHONY: debug debug: go run $(LD_FLAGS) cmd/aterm/*.go 2>debug.log diff --git a/cmd/aterm/appdialogs/version.go b/cmd/aterm/appdialogs/version.go index 2aa762d..39d709e 100644 --- a/cmd/aterm/appdialogs/version.go +++ b/cmd/aterm/appdialogs/version.go @@ -7,5 +7,11 @@ import ( // PrintVersion prints a simple sentence that lists the current version and commit hash // Note: this should only be called _after_ parsing CLI options func PrintVersion() { - printfln("ATerm Version: %v Build Hash: %v", config.Version(), config.CommitHash()) + printline("ATerm Version:", config.Version(), " Build Hash:", config.CommitHash()) +} + +// PrintExtendedVersion prints more version information: the go runtime and the build date +// Note: this should only be called _after_ parsing CLI options +func PrintExtendedVersion() { + printline("Go runtime:", config.GoRuntime(), " Build Date:", config.BuildDate()) } diff --git a/cmd/aterm/climain.go b/cmd/aterm/climain.go index 199f54f..b414a06 100644 --- a/cmd/aterm/climain.go +++ b/cmd/aterm/climain.go @@ -21,7 +21,8 @@ func main() { appdialogs.PrintVersion() - if info.Flag() { + if info.Flag() || opts.PrintVersion { + appdialogs.PrintExtendedVersion() return // exit if they ask to print the version } diff --git a/cmd/aterm/config/cli_parser.go b/cmd/aterm/config/cli_parser.go index 2be28a4..df370c7 100644 --- a/cmd/aterm/config/cli_parser.go +++ b/cmd/aterm/config/cli_parser.go @@ -14,6 +14,7 @@ type CLIOptions struct { PrintConfig bool ForceFirstRun bool HardReset bool + PrintVersion bool } // ParseCLI parses all (supported) arguments from the command line and stores them in a CLIOptions @@ -27,7 +28,7 @@ func ParseCLI() CLIOptions { attachBoolFlag("print-config", "pc", "Print current configuration (post-command line arguments), then exits", false, &opts.PrintConfig) attachBoolFlag("reset", "", "Rerun first run to set up initial values", false, &opts.ForceFirstRun) attachBoolFlag("reset-hard", "", "Ignore the config file and rerun first run", false, &opts.HardReset) - + attachBoolFlag("v", "", "output the software version and build information", false, &opts.PrintVersion) flag.Parse() return opts }