feat: add --version flag and ldflags-injectable version variable#33
Merged
GustyCube merged 2 commits intoGustyCube:masterfrom Mar 7, 2026
Merged
feat: add --version flag and ldflags-injectable version variable#33GustyCube merged 2 commits intoGustyCube:masterfrom
GustyCube merged 2 commits intoGustyCube:masterfrom
Conversation
Add a `version` variable (default "dev") that can be set at build time via -ldflags, and a --version flag to print the version and exit. This enables release pipelines to embed the version at build time.
There was a problem hiding this comment.
Pull request overview
Adds build-time version injection and a CLI flag to surface that version from the membraned binary, supporting release pipelines and easier debugging of deployed artifacts.
Changes:
- Introduces a
versionvariable defaulting to"dev"that can be overridden via-ldflags -X. - Adds a
--version/-versionflag to print the binary version and exit.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cmd/membraned/main.go
Outdated
|
|
||
| if *showVersion { | ||
| fmt.Printf("membraned %s\n", version) | ||
| os.Exit(0) |
There was a problem hiding this comment.
Using os.Exit(0) in main bypasses any deferred cleanup/flush that might be added before this branch in the future. Since this is a normal successful path, prefer printing the version and then return from main instead.
Suggested change
| os.Exit(0) | |
| return |
Using return instead of os.Exit(0) respects deferred cleanup and is the idiomatic Go pattern for normal exit from main(). Addresses Copilot review feedback on PR GustyCube#33. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
versionvariable (default"dev") that can be set at build time via-ldflags "-X main.version=v1.0.0"--versionflag that prints the version and exitsTest plan
go build -ldflags "-X main.version=v1.0.0" ./cmd/membraned/ && ./membraned --version→ printsmembraned v1.0.0./membraned --version(without ldflags) → printsmembraned dev