From 67c8eccba82c38c2ad0147dacfef9d13fca7bf7e Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Tue, 4 Oct 2022 23:18:22 -0400 Subject: [PATCH] Replace embedding version info with buildinfo (#1328) * Replace embedding version info with buildinfo * Less verbosity --- Makefile | 2 +- flags/flags.go | 13 ++++++++++++- main.go | 7 +------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 378c8dbec..412d0f6d1 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ install: @echo "$$HEADER" @echo "Installing ${APP} with ${GOVERS}..." @go clean - @go install -ldflags="-s -w -X main.version=$(shell git describe --always --abbrev=6) -X main.date=$(shell date +%FT%T%z)" + @go install -ldflags="-s -w" @mv $(GOBIN)/wtf $(GOBIN)/${APP} $(eval INSTALLPATH = $(shell which ${APP})) @echo "${APP} installed into ${INSTALLPATH}" diff --git a/flags/flags.go b/flags/flags.go index 573e62d14..e28339cca 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "runtime/debug" "strings" "github.com/chzyer/readline" @@ -54,13 +55,23 @@ func (flags *Flags) ConfigFilePath() string { // RenderIf displays special-case information based on the flags passed // in, if any flags were passed in -func (flags *Flags) RenderIf(version, date string, config *config.Config) { +func (flags *Flags) RenderIf(config *config.Config) { if flags.HasModule() { help.Display(flags.Module, config) os.Exit(0) } if flags.HasVersion() { + info, _ := debug.ReadBuildInfo() + version := "dev" + date := "now" + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + version = setting.Value + } else if setting.Key == "vcs.time" { + date = setting.Value + } + } fmt.Printf("%s (%s)\n", version, date) os.Exit(0) } diff --git a/main.go b/main.go index a7093cea8..a70b2a357 100644 --- a/main.go +++ b/main.go @@ -21,11 +21,6 @@ import ( "github.com/wtfutil/wtf/wtf" ) -var ( - date = "dev" - version = "dev" -) - /* -------------------- Main -------------------- */ func main() { @@ -41,7 +36,7 @@ func main() { wtf.SetTerminal(config) - flags.RenderIf(version, date, config) + flags.RenderIf(config) if flags.Profile { defer profile.Start(profile.MemProfile).Stop()