From 9c73699c6590b91215b4dd22a5ba32221bb7929d Mon Sep 17 00:00:00 2001 From: Mike Fridman Date: Wed, 26 Jul 2023 08:46:24 -0400 Subject: [PATCH] refactor: use debug BuildInfo for version if available --- cmd/goose/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/goose/main.go b/cmd/goose/main.go index f3a58fdd6..26ebb37f3 100644 --- a/cmd/goose/main.go +++ b/cmd/goose/main.go @@ -1,6 +1,7 @@ package main import ( + _ "embed" "errors" "flag" "fmt" @@ -8,6 +9,7 @@ import ( "log" "os" "path/filepath" + "runtime/debug" "sort" "strconv" "strings" @@ -48,7 +50,11 @@ func main() { } if *versionFlag { - fmt.Printf("goose version: %s\n", version) + buildInfo, ok := debug.ReadBuildInfo() + if ok && buildInfo != nil && buildInfo.Main.Version != "" { + version = buildInfo.Main.Version + } + fmt.Printf("goose version: %s\n", strings.TrimSpace(version)) return } if *verbose {