Show git commit and build time in vintner version

Uses Go's automatic VCS build-info stamping (vcs.revision/vcs.time/
vcs.modified, embedded by `go build` since Go 1.18 - no -ldflags
changes needed, works the same for a CI release build and a plain
local `go build`). Knowing the exact commit a bug report's binary was
built from, not just the X.Y.Z tag, is the point - two builds of the
same tag could still differ.

Split the pure formatting logic (formatVersion) from the
debug.ReadBuildInfo() call so it's actually unit-testable: `go test`
binaries don't get VCS stamping the way `go build` ones do, so there
was no way to exercise the revision-formatting branch through
versionString() itself.
This commit is contained in:
Cheviiot
2026-07-25 11:37:02 +10:00
parent 6186837fd2
commit 94a19e6b43
3 changed files with 103 additions and 1 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ func runCLI(args []string) int {
case "completion":
return runCompletion(args[1:])
case "version", "v", "--version":
fmt.Println("vintner " + version)
fmt.Println(versionString())
return 0
case "-h", "--help", "help", "h":
printUsage()