Skip to content

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

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

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

Conversation

@DTTerastar

Copy link
Copy Markdown
Collaborator

Problem

crono-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
crono-export version dev
$ go build -ldflags "-X github.com/quantcli/crono-export-cli/cmd.version=v9.9.9" -o b . && ./b --version
crono-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
@DTTerastar
DTTerastar merged commit 4b5f2b7 into main Jul 30, 2026
3 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