Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/fix-read-format-collision.md
Original file line number Diff line number Diff line change
@@ -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`.
8 changes: 4 additions & 4 deletions crates/google-workspace-cli/src/helpers/gmail/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,9 @@ Use fragment tags (<p>, <b>, <a>, etc.) — no <html>/<body> 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"),
)
Expand All @@ -1831,7 +1831,7 @@ Use fragment tags (<p>, <b>, <a>, etc.) — no <html>/<body> 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.
Expand Down
2 changes: 1 addition & 1 deletion crates/google-workspace-cli/src/helpers/gmail/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(super) async fn handle_read(
fetch_message_metadata(&client, &t, message_id).await?
};

let format = matches.get_one::<String>("format").unwrap();
let format = matches.get_one::<String>("body-format").unwrap();
let show_headers = matches.get_flag("headers");
let use_html = matches.get_flag("html");

Expand Down
9 changes: 2 additions & 7 deletions crates/google-workspace-cli/src/helpers/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,8 @@ fn process_file(path: &Path) -> Result<Option<serde_json::Value>, 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),
};

Expand Down
Loading