Skip to content

Silence cobra usage/error dump on failure (#31)#52

Open
vinistoisr wants to merge 1 commit into
quantcli:mainfrom
vinistoisr:fix/31-silence-cobra-usage
Open

Silence cobra usage/error dump on failure (#31)#52
vinistoisr wants to merge 1 commit into
quantcli:mainfrom
vinistoisr:fix/31-silence-cobra-usage

Conversation

@vinistoisr

Copy link
Copy Markdown

Fixes #31.

Problem

Cobra prints the full usage/flags block to stderr on any RunE or flag-parse error. This clutters logs and buries the real message, breaking the "data on stdout, errors on stderr" contract. For example, a stray --version produced a full screen of usage text and exit code 1.

Fix

  • Set SilenceUsage: true and SilenceErrors: true on rootCmd.
  • Print a single-line Error: <msg> to stderr from Execute() ourselves.

stdout stays data-only; stderr carries one concise line.

Behavior after fix

$ liftoff-export --version
# stdout: (empty)
# stderr: Error: unknown flag: --version
# exit:   1

Tests

Adds TestRootCmd_NoUsageDumpOnError, asserting neither Usage: nor Available Commands: is emitted on a flag-parse error. go test ./... and go vet ./... pass.

🤖 Generated with Claude Code

Cobra prints the full usage and flags block to stderr on any RunE or
flag-parse error. That clutters logs and buries the real message,
breaking the "data on stdout, errors on stderr" contract: a stray flag
like `--version` produced a screenful of usage text.

Set SilenceUsage and SilenceErrors on the root command and print a
single-line "Error: <msg>" to stderr from Execute instead. stdout stays
data-only; stderr carries one concise line.

Adds a regression test asserting no usage/command block is emitted on a
flag-parse error.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On error, cobra usage/flags text is dumped to stderr (clutters logs and fails the 'data only on stdout, errors only on stderr' contract)

3 participants