fix: detect version from build info at runtime

Amolith created

Assisted-by: Claude Opus 4.5 via Crush

Change summary

main.go | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

Detailed changes

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
+}