From 7716053dc7729dfcc4c2e02bfeb276b1a1425a1f Mon Sep 17 00:00:00 2001 From: Sanjay Ramadugu Date: Thu, 20 Aug 2026 21:06:12 -0700 Subject: [PATCH] fix(cli): accept --format after a subcommand Add global=true to the format arg so --format parses after a subcommand as well as before it. Fixes block/buzz#6391 Signed-off-by: Sanjay Ramadugu Co-authored-by: Sanjay Ramadugu --- crates/buzz-cli/src/lib.rs | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/buzz-cli/src/lib.rs b/crates/buzz-cli/src/lib.rs index 5cac8c941e..7d078b3ac8 100644 --- a/crates/buzz-cli/src/lib.rs +++ b/crates/buzz-cli/src/lib.rs @@ -91,7 +91,7 @@ struct Cli { auth_tag: Option, /// Output format: 'json' (default, full fields) or 'compact' (reduced fields). - #[arg(long, value_enum, default_value = "json")] + #[arg(long, value_enum, default_value = "json", global = true)] format: OutputFormat, #[command(subcommand)] @@ -161,7 +161,7 @@ impl std::fmt::Display for PresenceStatus { } /// Output format for read commands. -#[derive(Clone, clap::ValueEnum, Default)] +#[derive(Clone, Debug, PartialEq, clap::ValueEnum, Default)] pub enum OutputFormat { /// Full normalized JSON (default) #[default] @@ -2126,6 +2126,45 @@ mod tests { Cli::command().debug_assert(); } + #[test] + fn format_after_subcommand_parses() { + let uuid = "123e4567-e89b-12d3-a456-426614174000"; + let cli = Cli::try_parse_from([ + "buzz", + "messages", + "get", + "--format", + "compact", + "--channel", + uuid, + ]) + .unwrap(); + assert_eq!(cli.format, OutputFormat::Compact); + } + + #[test] + fn format_before_subcommand_parses() { + let uuid = "123e4567-e89b-12d3-a456-426614174000"; + let cli = Cli::try_parse_from([ + "buzz", + "--format", + "compact", + "messages", + "get", + "--channel", + uuid, + ]) + .unwrap(); + assert_eq!(cli.format, OutputFormat::Compact); + } + + #[test] + fn format_defaults_to_json() { + let uuid = "123e4567-e89b-12d3-a456-426614174000"; + let cli = Cli::try_parse_from(["buzz", "messages", "get", "--channel", uuid]).unwrap(); + assert_eq!(cli.format, OutputFormat::Json); + } + #[test] fn messages_thread_accepts_link_or_explicit_identifiers() { let channel = "123e4567-e89b-12d3-a456-426614174000";