From 11d667a447a1de7c35faa180745761906a32f359 Mon Sep 17 00:00:00 2001 From: "Snow W. Lee (Sungwon)" Date: Mon, 27 Jul 2026 07:11:58 +0900 Subject: [PATCH] fix(cli): report the real version for go-install builds (#47) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit go install github.com/runbear-io/beardrive/cmd/bdrive@latest skips the release ldflags, so every module-built binary claimed to be 0.1.0-dev — useless in beta bug reports. Fall back to the module version Go stamps into the binary (debug.ReadBuildInfo) when ldflags didn't set one. Found during the BEA-33 fresh-machine quickstart check. Co-authored-by: Claude Fable 5 --- cmd/bdrive/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/bdrive/main.go b/cmd/bdrive/main.go index 4915bda..cf12319 100644 --- a/cmd/bdrive/main.go +++ b/cmd/bdrive/main.go @@ -6,6 +6,8 @@ package main import ( "fmt" "os" + "runtime/debug" + "strings" "github.com/spf13/cobra" @@ -13,8 +15,20 @@ import ( ) // version is set at release time via -ldflags "-X main.version=...". +// `go install …@vX.Y.Z` builds skip ldflags, so fall back to the module +// version Go stamps into the binary. var version = "0.1.0-dev" +func resolvedVersion() string { + if version != "0.1.0-dev" { + return version + } + if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" && bi.Main.Version != "(devel)" { + return strings.TrimPrefix(bi.Main.Version, "v") + } + return version +} + func main() { root := &cobra.Command{ Use: "bdrive", @@ -28,7 +42,7 @@ Cloud). Every change is journaled — you can always see which device and author changed which file, and when. Files are real files on disk, so everything keeps working offline; changes sync when the remote is reachable.`, SilenceUsage: true, - Version: version, + Version: resolvedVersion(), } root.SetVersionTemplate("beardrive {{.Version}}\n") root.AddCommand( @@ -61,7 +75,7 @@ func versionCmd() *cobra.Command { Use: "version", Short: "Print the bdrive version", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("beardrive", version) + fmt.Println("beardrive", resolvedVersion()) }, } }