Print a real version from a go install build #18

Closed
opened 2026-09-21 09:18:05 +02:00 by clawbot · 1 comment
Collaborator

keyfunc --version prints the version only when the binary was built with make build, which stamps it with -ldflags. A binary from go install prints dev, so a user reporting a problem cannot say what they run.

Implementation

  • In internal/cli/cli.go: when Version is still dev, take the module version from runtime/debug.ReadBuildInfo() (Main.Version, when it is set and not (devel)). The stamped value wins when present. Standard library only.

Definition of done

  • A test covers the choice between the stamped value, the build info value and dev (the function that chooses takes the build info as an argument so the test needs no real build).
  • README's sentence on --version stays true.
  • make check green. Branch cut from next, PR base next. Wait for #17 to land first: it changes the same file.

Model: fable-5-1

`keyfunc --version` prints the version only when the binary was built with `make build`, which stamps it with `-ldflags`. A binary from `go install` prints `dev`, so a user reporting a problem cannot say what they run. ## Implementation - In `internal/cli/cli.go`: when `Version` is still `dev`, take the module version from `runtime/debug.ReadBuildInfo()` (`Main.Version`, when it is set and not `(devel)`). The stamped value wins when present. Standard library only. ## Definition of done - A test covers the choice between the stamped value, the build info value and `dev` (the function that chooses takes the build info as an argument so the test needs no real build). - README's sentence on `--version` stays true. - `make check` green. Branch cut from `next`, PR base `next`. Wait for https://git.eeqj.de/sneak/keyfunc/issues/17 to land first: it changes the same file. Model: fable-5-1
clawbot self-assigned this 2026-09-21 09:18:05 +02:00
Author
Collaborator

Done in #26 (base next).

When --version would otherwise print dev, it now falls back to the module version from runtime/debug.ReadBuildInfo(), so a go install build reports a real version. A build-time stamp still wins, and the (devel) of a local build is ignored. The choosing function takes the build info as an argument and is covered by a test with no real build. README updated.

Note: I started now rather than after #17 per the reorder; 17 rebases onto this.

Model: opus-4-8

Done in https://git.eeqj.de/sneak/keyfunc/pulls/26 (base `next`). When `--version` would otherwise print `dev`, it now falls back to the module version from `runtime/debug.ReadBuildInfo()`, so a `go install` build reports a real version. A build-time stamp still wins, and the `(devel)` of a local build is ignored. The choosing function takes the build info as an argument and is covered by a test with no real build. README updated. Note: I started now rather than after https://git.eeqj.de/sneak/keyfunc/issues/17 per the reorder; 17 rebases onto this. Model: opus-4-8
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/keyfunc#18