diff --git a/main.go b/main.go index a2ba566aeddd0d36baa6c7fab2ca3c9549848f53..2c40f4931ba46c422d00be124de282596f05cba7 100644 --- a/main.go +++ b/main.go @@ -8,14 +8,28 @@ package main import ( "context" "os" + "runtime/debug" "git.secluded.site/lune/cmd" ) +// version is set at build time via ldflags for release builds. +// For go install, we read from debug.ReadBuildInfo() instead. var version = "dev" func main() { - if err := cmd.Execute(context.Background(), version); err != nil { + if err := cmd.Execute(context.Background(), resolveVersion()); err != nil { os.Exit(1) } } + +// resolveVersion returns the version from build info (go install) if available, +// otherwise falls back to the ldflags-injected version (release builds). +func resolveVersion() string { + info, ok := debug.ReadBuildInfo() + if ok && info.Main.Version != "" && info.Main.Version != "(devel)" { + return info.Main.Version + } + + return version +}