From b05e40a789cc15f8ab0bb00cbb67afba57812cbe Mon Sep 17 00:00:00 2001 From: DTTerastar Date: Thu, 30 Jul 2026 17:53:11 -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 0ca86f1..ad7bf37 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,6 +16,7 @@ builds: goarch: arm64 ldflags: - -s -w + - -X github.com/quantcli/liftoff-export-cli/cmd.version=v{{ .Version }} archives: - formats: diff --git a/cmd/root.go b/cmd/root.go index fc2eb54..f8adbdb 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/liftoff-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: "liftoff-export", - Short: "CLI for the Liftoff fitness app", + Use: "liftoff-export", + Short: "CLI for the Liftoff fitness app", + Version: version, Long: `liftoff-export reads your personal Liftoff (gymbros.com) workout and bodyweight data and prints it on stdout. Default output is narrow, fitdown-style markdown; pass --format json for the full structured row.