From 892e4db6de9a83cfb52187f78f75f5bd8b539912 Mon Sep 17 00:00:00 2001 From: DTTerastar Date: Thu, 30 Jul 2026 17:53:12 -0400 Subject: [PATCH] feat(cmd): add --version, wired to the release tag via ldflags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `--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) Claude-Session: https://claude.ai/code/session_012MvqxTC64Z9EEDewCUbNNo --- .goreleaser.yml | 1 + cmd/root.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index d2858be..01db286 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,6 +16,7 @@ builds: goarch: arm64 ldflags: - -s -w + - -X github.com/quantcli/crono-export-cli/cmd.version=v{{ .Version }} archives: - formats: diff --git a/cmd/root.go b/cmd/root.go index 9da3341..d4d98b6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,9 +8,15 @@ import ( "github.com/spf13/cobra" ) +// version is overwritten at release time via +// -ldflags "-X github.com/quantcli/crono-export-cli/cmd.version=v1.1.0". +// Setting rootCmd.Version below makes cobra register --version for free. +var version = "dev" + var rootCmd = &cobra.Command{ - Use: "crono-export", - Short: "Export Cronometer nutrition, biometrics, and food log data", + Use: "crono-export", + Short: "Export Cronometer nutrition, biometrics, and food log data", + Version: version, Long: `crono-export reads your personal Cronometer data via the same export endpoints the web app uses and prints it on stdout. Default output is narrow, fitdown-style markdown; pass --format json for the full