Skip to content

fix(cli): accept --format after a subcommand - #6464

Open
sanjay3290 wants to merge 1 commit into
block:mainfrom
sanjay3290:fix/cli-format-global
Open

fix(cli): accept --format after a subcommand#6464
sanjay3290 wants to merge 1 commit into
block:mainfrom
sanjay3290:fix/cli-format-global

Conversation

@sanjay3290

Copy link
Copy Markdown

Problem

Fixes #6391.

--format is declared on the top-level Cli struct without global = true, so clap only accepts it before the subcommand:

$ buzz --format compact messages get --channel <uuid>   # works
$ buzz messages get --format compact --channel <uuid>   # error: unexpected argument '--format'

The second form is what people actually type, and it is how every other CLI treats an output-format flag.

Change

One line: add global = true to the format arg. OutputFormat also gains Debug and PartialEq so the tests can assert on it.

Tests

Three tests in the existing mod tests, all driving the real Cli parser via Cli::try_parse_from, not a synthetic command:

  • format_after_subcommand_parses — the previously broken form; fails on main with an unexpected-argument error.
  • format_before_subcommand_parses — the form that already worked, so the fix does not trade one position for the other.
  • format_defaults_to_json — the default survives.

Deletion probe: removing global = true makes format_after_subcommand_parses fail.

Verification

cargo fmt --all -- --check                              # clean
cargo clippy --workspace --all-targets -- -D warnings   # clean
cargo test -p buzz-cli                                  # 366 passed, 0 failed

Add global=true to the format arg so --format parses after a
subcommand as well as before it.

Fixes block#6391

Signed-off-by: Sanjay Ramadugu <sramadugu1@gmail.com>
Co-authored-by: Sanjay Ramadugu <sramadugu1@gmail.com>
@sanjay3290
sanjay3290 requested a review from a team as a code owner August 21, 2026 06:09
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.

global --format after a subcommand fails with an unhelpful clap error

1 participant