From b81140eafaa3d01fb0e5b7eefdf1a30bf106870d Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Sun, 26 Apr 2026 00:10:45 +0000 Subject: [PATCH] fix: exit non-zero and print help to stderr for bare auth/root invocations Bare `withings-export auth` and `withings-export` (no subcommand) previously printed help to stdout and exited 0, polluting stdout for shell-script consumers and misleading callers into thinking a subcommand had succeeded. Now both commands print help to stderr and return exit code 1 when no subcommand is given. Closes #28 Co-authored-by: Darrell --- cmd/auth.go | 10 ++++++++-- cmd/root.go | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/auth.go b/cmd/auth.go index 016bf79..33bd47d 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -12,8 +12,14 @@ import ( ) var authCmd = &cobra.Command{ - Use: "auth", - Short: "Authentication commands", + Use: "auth", + Short: "Authentication commands", + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + cmd.SetOut(cmd.ErrOrStderr()) + _ = cmd.Help() + return fmt.Errorf("subcommand required") + }, } var loginCmd = &cobra.Command{ diff --git a/cmd/root.go b/cmd/root.go index 70b5ba4..7544c06 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,14 +1,16 @@ package cmd import ( + "fmt" "os" "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ - Use: "withings-export", - Short: "CLI to export health data from Withings", + Use: "withings-export", + Short: "CLI to export health data from Withings", + SilenceUsage: true, Long: `withings-export reads your personal Withings health data — activity, sleep, workouts, body measurements, intraday samples — and prints it on stdout. Default output is narrow, fitdown-style markdown; pass @@ -16,6 +18,11 @@ stdout. Default output is narrow, fitdown-style markdown; pass LLM agents: run 'withings-export prime' for a one-screen orientation (I/O contract, subcommands, date flags, jq recipes).`, + RunE: func(cmd *cobra.Command, args []string) error { + cmd.SetOut(cmd.ErrOrStderr()) + _ = cmd.Help() + return fmt.Errorf("subcommand required") + }, } func Execute() {