Add --version option #64

Merged
danny merged 2 commits from issue23_version_option into main 2026-07-05 18:39:26 +01:00
danny commented 2026-07-05 18:25:01 +01:00 (Migrated from gitlab.keyop.co.uk)

Closes #23 (https://gitlab.keyop.co.uk/keyop/go/nfq_forwarder/-/issues/23).

Summary

No version string existed anywhere in the binary before this - releases were purely git tags
(vX.Y.Z) with nothing for a CLI flag to report. This adds a --version option that prints the
version the running binary was built from.

  • cmd/main.go gets a version package variable, defaulting to "dev" for a plain go build/go run outside the release pipeline.
  • .goreleaser.yaml's builds.ldflags stamps a version string into that variable at build time,
    distinguishing a real release from everything else:
    • A real, tagged release build (goreleaser release, from a pushed vX.Y.Z tag) prints just
      the tag, e.g. v1.0.2.
    • Any other build (make build/make package, or CI runs other than the tag-triggered
      release job) isn't actually that release, so printing the bare tag would be misleading -
      it instead prints the most recent tag plus a short commit reference, e.g.
      v1.0.2-dev-5809daf.
  • cmd/setup.NewApp takes a new version string parameter, plumbed through from cmd/main.go.
  • --version is a plain boolean flag with no short alias - -v is already --verbose in
    this CLI, and urfave/cli's own built-in --version/-v auto-injected flag would collide
    with that, so NewApp sets HideVersion: true and handles --version explicitly in Action
    instead (checked first, before resolveConfiguration - works regardless of --config/any
    other flag, and does no iptables/capability/netlink work).

Verified manually with a real snapshot build (make build):

$ ./dist/nfq_forwarder --version
nfq_forwarder v1.0.2-dev-5809daf

and confirmed --help shows both --version and --verbose, -v with no conflict.

Test plan

  • go build ./..., go vet ./...
  • make lint (golangci-lint + yamllint)
  • make test (go test -race -cover ./...)
  • New tests: version flag has no alias (regression guard against the -v collision),
    versionString output format, updated TestNewApp flag count/HideVersion assertion
  • Manual snapshot build + --version/--help sanity check (see above), confirming both the
    release-tag format and the snapshot <tag>-dev-<commit> format

Docs

Updated README.md, docs/README.md, docs/config.example.yaml, and CLAUDE.md (Design
notes + Testing sections) to document the new flag and how the version is stamped in.

Closes #23 (https://gitlab.keyop.co.uk/keyop/go/nfq_forwarder/-/issues/23). ## Summary No version string existed anywhere in the binary before this - releases were purely git tags (`vX.Y.Z`) with nothing for a CLI flag to report. This adds a `--version` option that prints the version the running binary was built from. - `cmd/main.go` gets a `version` package variable, defaulting to `"dev"` for a plain `go build`/`go run` outside the release pipeline. - `.goreleaser.yaml`'s `builds.ldflags` stamps a version string into that variable at build time, distinguishing a real release from everything else: - A real, tagged release build (`goreleaser release`, from a pushed `vX.Y.Z` tag) prints just the tag, e.g. `v1.0.2`. - Any other build (`make build`/`make package`, or CI runs other than the tag-triggered `release` job) isn't actually that release, so printing the bare tag would be misleading - it instead prints the most recent tag plus a short commit reference, e.g. `v1.0.2-dev-5809daf`. - `cmd/setup.NewApp` takes a new `version string` parameter, plumbed through from `cmd/main.go`. - `--version` is a plain boolean flag with **no short alias** - `-v` is already `--verbose` in this CLI, and `urfave/cli`'s own built-in `--version`/`-v` auto-injected flag would collide with that, so `NewApp` sets `HideVersion: true` and handles `--version` explicitly in `Action` instead (checked first, before `resolveConfiguration` - works regardless of `--config`/any other flag, and does no iptables/capability/netlink work). Verified manually with a real snapshot build (`make build`): ``` $ ./dist/nfq_forwarder --version nfq_forwarder v1.0.2-dev-5809daf ``` and confirmed `--help` shows both `--version` and `--verbose, -v` with no conflict. ## Test plan - [x] `go build ./...`, `go vet ./...` - [x] `make lint` (golangci-lint + yamllint) - [x] `make test` (`go test -race -cover ./...`) - [x] New tests: `version` flag has no alias (regression guard against the `-v` collision), `versionString` output format, updated `TestNewApp` flag count/`HideVersion` assertion - [x] Manual snapshot build + `--version`/`--help` sanity check (see above), confirming both the release-tag format and the snapshot `<tag>-dev-<commit>` format ## Docs Updated `README.md`, `docs/README.md`, `docs/config.example.yaml`, and `CLAUDE.md` (Design notes + Testing sections) to document the new flag and how the version is stamped in.
danny (Migrated from gitlab.keyop.co.uk) approved these changes 2026-07-05 18:25:01 +01:00
danny commented 2026-07-05 18:34:24 +01:00 (Migrated from gitlab.keyop.co.uk)

added 1 commit

  • 4ace075b - Report tag+commit for non-release builds instead of a bare tag

Compare with previous version

added 1 commit <ul><li>4ace075b - Report tag+commit for non-release builds instead of a bare tag</li></ul> [Compare with previous version](/keyop/go/nfq_forwarder/-/merge_requests/23/diffs?diff_id=276&start_sha=5809daf6e4f96b904b5577c82b0214ee7d7dbede)
danny commented 2026-07-05 18:34:42 +01:00 (Migrated from gitlab.keyop.co.uk)

changed the description

changed the description
danny commented 2026-07-05 18:38:03 +01:00 (Migrated from gitlab.keyop.co.uk)

assigned to @danny

assigned to @danny
danny commented 2026-07-05 18:38:03 +01:00 (Migrated from gitlab.keyop.co.uk)

requested review from @danny

requested review from @danny
danny commented 2026-07-05 18:38:37 +01:00 (Migrated from gitlab.keyop.co.uk)

LGTM, and all appears to work as intended.

Good work.

LGTM, and all appears to work as intended. Good work.
danny commented 2026-07-05 18:38:37 +01:00 (Migrated from gitlab.keyop.co.uk)

approved this merge request

approved this merge request
danny (Migrated from gitlab.keyop.co.uk) merged commit afe0c4e4a4 into main 2026-07-05 18:39:26 +01:00
danny commented 2026-07-05 18:39:27 +01:00 (Migrated from gitlab.keyop.co.uk)

mentioned in commit afe0c4e4a4

mentioned in commit afe0c4e4a4c254b764f6adb2eb0b716b23c6b0dd
danny commented 2026-07-06 07:42:19 +01:00 (Migrated from gitlab.keyop.co.uk)

mentioned in commit 4c2d0a6135

mentioned in commit 4c2d0a61355b2822dab32c85f4abe3cd31793cf0
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
keyop-go/nfq_forwarder!64
No description provided.