From 6286cf118dd13b2340ba61018ab0c68f333d8509 Mon Sep 17 00:00:00 2001 From: DTTerastar Date: Thu, 30 Jul 2026 15:31:47 -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 `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) Claude-Session: https://claude.ai/code/session_012MvqxTC64Z9EEDewCUbNNo --- .goreleaser.yml | 1 + cmd/root.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 763e1ee..5a65946 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,6 +16,7 @@ builds: goarch: arm64 ldflags: - -s -w + - -X github.com/quantcli/withings-export-cli/cmd.version=v{{ .Version }} archives: - formats: diff --git a/cmd/root.go b/cmd/root.go index 7544c06..6410f2a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,9 +7,15 @@ import ( "github.com/spf13/cobra" ) +// version is overwritten at release time via +// -ldflags "-X github.com/quantcli/withings-export-cli/cmd.version=v1.2.0". +// Setting rootCmd.Version below makes cobra register --version for free. +var version = "dev" + var rootCmd = &cobra.Command{ Use: "withings-export", Short: "CLI to export health data from Withings", + Version: version, SilenceUsage: true, Long: `withings-export reads your personal Withings health data — activity, sleep, workouts, body measurements, intraday samples — and prints it on