Skip to content

Commit 9a20e0c

Browse files
fgksgfclaude
andauthored
Fix version output for go install installations (#203)
When users install license-eye via `go install`, the version shows "dev" instead of the correct version number. This happens because go install doesn't use the Makefile's -ldflags to inject version information. This fix adds a fallback mechanism that reads version information from build metadata when ldflags injection is not available, while maintaining full compatibility with existing build processes. Changes: - Add runtime/debug import to read build information - Implement version fallback: ldflags → build info → "dev" - Maintain backward compatibility with existing Makefile builds - Users installing via go install will now see correct version 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 049742d commit 9a20e0c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

commands/version.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@
1717

1818
package commands
1919

20+
import (
21+
"runtime/debug"
22+
)
23+
2024
var version = "dev"
25+
26+
func init() {
27+
// Try to get version from build info first (for go install)
28+
if info, ok := debug.ReadBuildInfo(); ok {
29+
if info.Main.Version != "" && info.Main.Version != "(devel)" {
30+
version = info.Main.Version
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)