Get version from built metadata
All checks were successful
Build and Publish / release (push) Successful in 1m5s

This commit is contained in:
Ryan McGuire 2024-12-31 20:58:24 -05:00
parent 870760443e
commit f14bc47c7b

View File

@ -6,6 +6,7 @@ import (
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime/debug"
"strings" "strings"
"github.com/pterm/pterm" "github.com/pterm/pterm"
@ -83,7 +84,7 @@ func init() {
rootCmd.AddCommand(project.ProjectCmd) rootCmd.AddCommand(project.ProjectCmd)
// Version // Version
rootCmd.Version = Version rootCmd.Version = getVersion()
} }
// initConfig reads in config file and ENV variables if set. // initConfig reads in config file and ENV variables if set.
@ -172,3 +173,10 @@ func checkConfigPerms(file string) {
os.Exit(1) os.Exit(1)
} }
} }
func getVersion() string {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" {
return info.Main.Version
}
return Version
}