From 09395aa4a45cdab142aebc15988e64c3bdf8f83f Mon Sep 17 00:00:00 2001 From: Hoyt Harness <2735828+hoyt-harness@users.noreply.github.com> Date: Wed, 22 Apr 2026 12:52:48 -0500 Subject: [PATCH] fix(gmail): rename +read --format to --body-format to avoid global flag collision The +read subcommand defined a local --format arg (default: "text") that shared its name with the global --format flag (declared .global(true)). clap propagated the "text" default up to the root matches, causing main.rs to emit a spurious "unknown output format 'text'" warning on every +read invocation. Rename the arg to --body-format to eliminate the collision. The global --format flag is now unambiguous for +read; --body-format text (default) renders plain text and --body-format json returns the structured JSON object as before. Also collapse pre-existing clippy::collapsible_match in helpers/script.rs. --- .changeset/fix-read-format-collision.md | 19 +++++++++++++++++++ .../src/helpers/gmail/mod.rs | 8 ++++---- .../src/helpers/gmail/read.rs | 2 +- .../src/helpers/script.rs | 9 ++------- 4 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 .changeset/fix-read-format-collision.md diff --git a/.changeset/fix-read-format-collision.md b/.changeset/fix-read-format-collision.md new file mode 100644 index 00000000..8f381d11 --- /dev/null +++ b/.changeset/fix-read-format-collision.md @@ -0,0 +1,19 @@ +--- +"@googleworkspace/cli": patch +--- + +Fix `+read` local `--format` arg colliding with the global `--format` flag. + +Previously, `gmail +read` defined a local `--format` arg (values: `text`, `json`, +default: `text`). Because the global `--format` flag is declared with +`.global(true)`, clap propagated the `text` default up to the parent matches, +causing `main.rs` to emit a spurious `"unknown output format 'text'; falling back +to json"` warning on every `+read` invocation. + +The local arg is renamed to `--body-format` to eliminate the name collision. +`--body-format text` (default) renders the decoded message body as plain text; +`--body-format json` returns the full structured JSON object, matching the previous +`--format json` behaviour. + +**Migration note:** Scripts or aliases using `gws gmail +read --format json` must +be updated to `gws gmail +read --body-format json`. diff --git a/crates/google-workspace-cli/src/helpers/gmail/mod.rs b/crates/google-workspace-cli/src/helpers/gmail/mod.rs index caeb8b6b..da6e5625 100644 --- a/crates/google-workspace-cli/src/helpers/gmail/mod.rs +++ b/crates/google-workspace-cli/src/helpers/gmail/mod.rs @@ -1808,9 +1808,9 @@ Use fragment tags (

, , , etc.) — no / wrapper needed. .action(ArgAction::SetTrue), ) .arg( - Arg::new("format") - .long("format") - .help("Output format (text, json)") + Arg::new("body-format") + .long("body-format") + .help("Body rendering format: text (default) or json") .value_parser(["text", "json"]) .default_value("text"), ) @@ -1831,7 +1831,7 @@ Use fragment tags (

, , , etc.) — no / wrapper needed. EXAMPLES: gws gmail +read --id 18f1a2b3c4d gws gmail +read --id 18f1a2b3c4d --headers - gws gmail +read --id 18f1a2b3c4d --format json | jq '.body' + gws gmail +read --id 18f1a2b3c4d --body-format json | jq '.body_text' TIPS: Converts HTML-only messages to plain text automatically. diff --git a/crates/google-workspace-cli/src/helpers/gmail/read.rs b/crates/google-workspace-cli/src/helpers/gmail/read.rs index c09d0858..1a8ec5c2 100644 --- a/crates/google-workspace-cli/src/helpers/gmail/read.rs +++ b/crates/google-workspace-cli/src/helpers/gmail/read.rs @@ -35,7 +35,7 @@ pub(super) async fn handle_read( fetch_message_metadata(&client, &t, message_id).await? }; - let format = matches.get_one::("format").unwrap(); + let format = matches.get_one::("body-format").unwrap(); let show_headers = matches.get_flag("headers"); let use_html = matches.get_flag("html"); diff --git a/crates/google-workspace-cli/src/helpers/script.rs b/crates/google-workspace-cli/src/helpers/script.rs index 11bcdebe..6acd1618 100644 --- a/crates/google-workspace-cli/src/helpers/script.rs +++ b/crates/google-workspace-cli/src/helpers/script.rs @@ -169,13 +169,8 @@ fn process_file(path: &Path) -> Result, GwsError> { filename.trim_end_matches(".js").trim_end_matches(".gs"), ), "html" => ("HTML", filename.trim_end_matches(".html")), - "json" => { - if filename == "appsscript.json" { - ("JSON", "appsscript") - } else { - return Ok(None); - } - } + "json" if filename == "appsscript.json" => ("JSON", "appsscript"), + "json" => return Ok(None), _ => return Ok(None), };