From f14bc47c7b7774792612004a63f4f89c20f9b2d6 Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Tue, 31 Dec 2024 20:58:24 -0500 Subject: [PATCH] Get version from built metadata --- cmd/root.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 07e07cd..c8dd385 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,6 +6,7 @@ import ( "os/signal" "path/filepath" "regexp" + "runtime/debug" "strings" "github.com/pterm/pterm" @@ -83,7 +84,7 @@ func init() { rootCmd.AddCommand(project.ProjectCmd) // Version - rootCmd.Version = Version + rootCmd.Version = getVersion() } // initConfig reads in config file and ENV variables if set. @@ -172,3 +173,10 @@ func checkConfigPerms(file string) { os.Exit(1) } } + +func getVersion() string { + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" { + return info.Main.Version + } + return Version +}