Skip to content

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

Merged
DTTerastar merged 1 commit into
quantcli:mainfrom
vinistoisr:fix/31-silence-cobra-usage
Jul 21, 2026
Merged

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

Conversation

@vinistoisr

Copy link
Copy Markdown
Contributor

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>

@DTTerastar DTTerastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally: build, go vet, go test ./... all pass. Behavior confirmed — --version gives a single Error: unknown flag: --version on stderr with exit 1 and no usage block, while a bare invocation still prints help. Clean fix.

@DTTerastar
DTTerastar merged commit d4a2282 into quantcli:main Jul 21, 2026
5 checks passed
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