Add --version option #64
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
keyop-go/nfq_forwarder!64
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue23_version_option"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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--versionoption that prints theversion the running binary was built from.
cmd/main.gogets aversionpackage variable, defaulting to"dev"for a plaingo build/go runoutside the release pipeline..goreleaser.yaml'sbuilds.ldflagsstamps a version string into that variable at build time,distinguishing a real release from everything else:
goreleaser release, from a pushedvX.Y.Ztag) prints justthe tag, e.g.
v1.0.2.make build/make package, or CI runs other than the tag-triggeredreleasejob) 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.NewApptakes a newversion stringparameter, plumbed through fromcmd/main.go.--versionis a plain boolean flag with no short alias --vis already--verboseinthis CLI, and
urfave/cli's own built-in--version/-vauto-injected flag would collidewith that, so
NewAppsetsHideVersion: trueand handles--versionexplicitly inActioninstead (checked first, before
resolveConfiguration- works regardless of--config/anyother flag, and does no iptables/capability/netlink work).
Verified manually with a real snapshot build (
make build):and confirmed
--helpshows both--versionand--verbose, -vwith no conflict.Test plan
go build ./...,go vet ./...make lint(golangci-lint + yamllint)make test(go test -race -cover ./...)versionflag has no alias (regression guard against the-vcollision),versionStringoutput format, updatedTestNewAppflag count/HideVersionassertion--version/--helpsanity check (see above), confirming both therelease-tag format and the snapshot
<tag>-dev-<commit>formatDocs
Updated
README.md,docs/README.md,docs/config.example.yaml, andCLAUDE.md(Designnotes + Testing sections) to document the new flag and how the version is stamped in.
added 1 commit
4ace075b- Report tag+commit for non-release builds instead of a bare tagCompare with previous version
changed the description
assigned to @danny
requested review from @danny
LGTM, and all appears to work as intended.
Good work.
approved this merge request
mentioned in commit
afe0c4e4a4mentioned in commit
4c2d0a6135