Skip to content

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

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

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

Conversation

@DTTerastar

Copy link
Copy Markdown
Contributor

Problem

withings-export --version errors with unknown flag: --version. The binary carried no build-time version string, so there was nothing to print. (Noted pre-release across all three CLIs — withings is first to fix it.)

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 }}.

Test

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

$ go build -o we .                     # dev build
$ ./we --version
withings-export version dev

$ go build -ldflags "-X github.com/quantcli/withings-export-cli/cmd.version=v1.2.0" -o we .
$ ./we --version
withings-export version v1.2.0

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

🤖 Generated with Claude Code

https://claude.ai/code/session_012MvqxTC64Z9EEDewCUbNNo

`withings-export --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, and inject the tag
at release time via goreleaser ldflags. Unbuilt/dev builds report
"dev".

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
@DTTerastar
DTTerastar merged commit 59abfc0 into main Jul 30, 2026
7 checks passed
@DTTerastar
DTTerastar deleted the feat/version-flag branch July 30, 2026 19:35
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