Skip to content

feat(cmd): add --version flag - #59

Merged
DTTerastar merged 1 commit into
mainfrom
feat/version-flag
Jul 30, 2026
Merged

feat(cmd): add --version flag#59
DTTerastar merged 1 commit into
mainfrom
feat/version-flag

Conversation

@DTTerastar

Copy link
Copy Markdown
Collaborator

Problem

liftoff-export --version errors with unknown flag: --version. The binary carried no build-time version string, so there was nothing to print.

Change

  • Set cobra's rootCmd.Version from a package var version (default "dev"). Cobra registers --version (and -v) automatically once Version is non-empty — no custom subcommand.
  • Inject the release tag at build time via goreleaser ldflags: -X …/cmd.version=v{{ .Version }}.

Same pattern as quantcli/withings-export-cli#44, which is already released (v1.2.0).

Test

Manual, both paths (a build-tag injection isn't worth a unit test that would just exercise cobra):

$ go build -o b . && ./b --version
liftoff-export version dev
$ go build -ldflags "-X github.com/quantcli/liftoff-export-cli/cmd.version=v9.9.9" -o b . && ./b --version
liftoff-export version v9.9.9

go vet ./... / go test ./... green.

🤖 Generated with Claude Code

https://claude.ai/code/session_012MvqxTC64Z9EEDewCUbNNo

`--version` errored with `unknown flag` — the binary had no build-time
version to print. Set cobra's rootCmd.Version (which registers
--version/-v for free) from a package var, injected at release time via
goreleaser ldflags. Dev builds report "dev".

Matches the pattern shipped in withings-export-cli#44.

New minor flag, no behavior change to any existing command.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012MvqxTC64Z9EEDewCUbNNo
@github-actions

Copy link
Copy Markdown
Contributor

Try this PR without building it

Review binaries for commit b05e40a — direct download, no login required:

Platform Download
macOS (Intel) liftoff-export-darwin-amd64.zip
macOS (Apple silicon) liftoff-export-darwin-arm64.zip
Linux x86_64 liftoff-export-linux-amd64.zip
Linux arm64 liftoff-export-linux-arm64.zip
Windows x86_64 liftoff-export-windows-amd64.zip

Unzip, then on macOS/Linux chmod +x the binary before running. macOS Gatekeeper blocks unsigned binaries on first run — right-click → Open, or xattr -d com.apple.quarantine <file>.

Links are resolved by nightly.link, a third-party redirector for GitHub Actions artifacts, because GitHub has no anonymous artifact URL of its own. Signed-in users can also browse the run directly. Artifacts expire 14 days after the run. Updated on each push to this PR.

@DTTerastar
DTTerastar merged commit 0d2f7ff into main Jul 30, 2026
8 checks passed
@DTTerastar
DTTerastar deleted the feat/version-flag branch July 30, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant