Add --version option #23

Closed
opened 2026-07-05 18:13:22 +01:00 by danny · 6 comments
danny commented 2026-07-05 18:13:22 +01:00 (Migrated from gitlab.keyop.co.uk)

We should include a '--version' command line option in order to check the current release number.

We should include a '--version' command line option in order to check the current release number.
danny commented 2026-07-05 18:13:49 +01:00 (Migrated from gitlab.keyop.co.uk)

changed the description

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

Plan

nfq_forwarder currently has no version string baked into the binary at all - releases are pure
git tags (vX.Y.Z), so there's nothing for a --version flag to report yet. This plan adds one.

  • cmd/main.go: add a version package variable, defaulting to "dev" for a plain go build/go run outside the release pipeline.
  • .goreleaser.yaml: add ldflags: - -X main.version={{ .Tag }} to the builds: entry, so
    every snapshot (make build/make package) and released (make release, CI tag pipeline)
    binary is stamped with the exact git tag it was built from (e.g. v1.0.2) - matching how this
    project already refers to releases everywhere else (git tag, GitLab Release page URL).
  • cmd/setup.NewApp: takes a new version string parameter, passed through from
    cmd/main.go.
  • New --version flag (cmd/setup/setup.go's appFlags()): 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. Checked first, before
    resolveConfiguration, in NewApp's Action - works regardless of --config/any other flag,
    and does no iptables/capability/netlink work: prints nfq_forwarder <version> and exits
    successfully.
  • Testing: appFlags() gains a check that the version flag exists with no alias (matching
    the existing per-flag tests already in cmd/setup's test file); the version-string formatting
    is extracted into a small, directly-testable function. NewApp(...).Run(...) itself stays
    untested, consistent with the rest of this package (its Action always eventually reaches
    nfq_forwarder.NFQForwarderMain, which performs real system work and must never run in a
    test).

Work is happening on branch issue23_version_option; an MR will follow referencing this issue.

## Plan `nfq_forwarder` currently has no version string baked into the binary at all - releases are pure git tags (`vX.Y.Z`), so there's nothing for a `--version` flag to report yet. This plan adds one. - **`cmd/main.go`**: add a `version` package variable, defaulting to `"dev"` for a plain `go build`/`go run` outside the release pipeline. - **`.goreleaser.yaml`**: add `ldflags: - -X main.version={{ .Tag }}` to the `builds:` entry, so every snapshot (`make build`/`make package`) and released (`make release`, CI tag pipeline) binary is stamped with the exact git tag it was built from (e.g. `v1.0.2`) - matching how this project already refers to releases everywhere else (git tag, GitLab Release page URL). - **`cmd/setup.NewApp`**: takes a new `version string` parameter, passed through from `cmd/main.go`. - **New `--version` flag** (`cmd/setup/setup.go`'s `appFlags()`): 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. Checked first, before `resolveConfiguration`, in `NewApp`'s `Action` - works regardless of `--config`/any other flag, and does no iptables/capability/netlink work: prints `nfq_forwarder <version>` and exits successfully. - **Testing**: `appFlags()` gains a check that the `version` flag exists with no alias (matching the existing per-flag tests already in `cmd/setup`'s test file); the version-string formatting is extracted into a small, directly-testable function. `NewApp(...).Run(...)` itself stays untested, consistent with the rest of this package (its `Action` always eventually reaches `nfq_forwarder.NFQForwarderMain`, which performs real system work and must never run in a test). Work is happening on branch `issue23_version_option`; an MR will follow referencing this issue.
danny commented 2026-07-05 18:24:42 +01:00 (Migrated from gitlab.keyop.co.uk)

mentioned in commit 5809daf6e4

mentioned in commit 5809daf6e4f96b904b5577c82b0214ee7d7dbede
danny commented 2026-07-05 18:25:06 +01:00 (Migrated from gitlab.keyop.co.uk)

mentioned in merge request !64

mentioned in merge request !64
danny commented 2026-07-05 18:39:26 +01:00 (Migrated from gitlab.keyop.co.uk)

mentioned in commit afe0c4e4a4

mentioned in commit afe0c4e4a4c254b764f6adb2eb0b716b23c6b0dd
danny (Migrated from gitlab.keyop.co.uk) closed this issue 2026-07-05 18:39:27 +01:00
danny commented 2026-07-05 18:42:55 +01:00 (Migrated from gitlab.keyop.co.uk)

MR is approved and merged, and appears to do what has been requested. Separately asked Claude to ensure that non-tagged releases should be given a version of vX.Y.Z-dev-<commit> where X.Y.Z is the most recent tag, and commit is the abbreviated latest git release on the branch. This also works correctly.

v1.0.3. is being released now - closing this ticket.

MR is approved and merged, and appears to do what has been requested. Separately asked Claude to ensure that non-tagged releases should be given a version of `vX.Y.Z-dev-<commit>` where X.Y.Z is the most recent tag, and `commit` is the abbreviated latest git release on the branch. This also works correctly. v1.0.3. is being released now - closing this ticket.
Sign in to join this conversation.
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#23
No description provided.