Skip to content

fix(cli): print usage to stderr when a command fails - #17

Open
harshpuri84 wants to merge 1 commit into
bee-computer:mainfrom
harshpuri84:fix/usage-on-stderr
Open

harshpuri84 wants to merge 1 commit into
bee-computer:mainfrom
harshpuri84:fix/usage-on-stderr

Conversation

@harshpuri84

Copy link
Copy Markdown

When a command fails, bee prints the error to stderr and then the command's usage text to stdout. Anything reading stdout gets help text mixed into its data. With bee stream --json, the usage lines land inside the JSON event feed.

This change keeps help where the user asked for it and moves the rest out of the way:

  • bee --help, bee <command> --help and bee with no arguments still print help to stdout.
  • An unknown command, or a command that fails, prints its usage to stderr, after the error message.

printHelp and printCommandHelp take a write function, default console.log. The two failure paths pass console.error.

Testing

  • New sources/main.test.ts runs the CLI as a user would: requested help lands on stdout, an unknown command and a failing command put usage on stderr and leave stdout empty. It needs no network and no login.
  • bun run typecheck, bun run build and bun test (314 pass, 0 fail) are clean.

Independent of #16; each applies on its own.

🤖 Generated with Claude Code

Help the user asked for (--help, or no arguments) stays on stdout. Usage
printed because a command failed or was unknown now goes to stderr, so it
never mixes into output another program reads, such as
`bee stream --json`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant