Skip to content

Commit 4b5f2b7

Browse files
DTTerastarclaude
andauthored
feat(cmd): add --version, wired to the release tag via ldflags (#49)
`--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. Claude-Session: https://claude.ai/code/session_012MvqxTC64Z9EEDewCUbNNo Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2089d63 commit 4b5f2b7

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ builds:
1616
goarch: arm64
1717
ldflags:
1818
- -s -w
19+
- -X github.com/quantcli/crono-export-cli/cmd.version=v{{ .Version }}
1920

2021
archives:
2122
- formats:

cmd/root.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11+
// version is overwritten at release time via
12+
// -ldflags "-X github.com/quantcli/crono-export-cli/cmd.version=v1.1.0".
13+
// Setting rootCmd.Version below makes cobra register --version for free.
14+
var version = "dev"
15+
1116
var rootCmd = &cobra.Command{
12-
Use: "crono-export",
13-
Short: "Export Cronometer nutrition, biometrics, and food log data",
17+
Use: "crono-export",
18+
Short: "Export Cronometer nutrition, biometrics, and food log data",
19+
Version: version,
1420
Long: `crono-export reads your personal Cronometer data via the same export
1521
endpoints the web app uses and prints it on stdout. Default output is
1622
narrow, fitdown-style markdown; pass --format json for the full

0 commit comments

Comments
 (0)