From 5d8ac7f1c82fa19eb3361c5d366e25a12fc6d385 Mon Sep 17 00:00:00 2001 From: Amolith Date: Thu, 25 Dec 2025 15:29:22 -0700 Subject: [PATCH] fix: detect version from build info at runtime Assisted-by: Claude Opus 4.5 via Crush --- main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 +}