From 5b73417937fb89c1da05416b0461f504db20b58e Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sun, 5 Apr 2026 21:45:02 -0700 Subject: [PATCH 1/4] fix(helpers): respect --format flag in sheets +append, +read, and docs +write These helpers hard-coded OutputFormat::default() (JSON) when invoking executor::execute_method, so --format table/yaml/csv had no effect. Each handler now reads the global --format flag from ArgMatches and passes it through, matching the behaviour of calendar +agenda and gmail +triage. --- .changeset/helpers-respect-format-flag.md | 12 ++++++++++++ crates/google-workspace-cli/src/helpers/docs.rs | 6 +++++- crates/google-workspace-cli/src/helpers/sheets.rs | 12 ++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .changeset/helpers-respect-format-flag.md diff --git a/.changeset/helpers-respect-format-flag.md b/.changeset/helpers-respect-format-flag.md new file mode 100644 index 00000000..796a3aa7 --- /dev/null +++ b/.changeset/helpers-respect-format-flag.md @@ -0,0 +1,12 @@ +--- +"@googleworkspace/cli": patch +--- + +Fix `--format` flag being silently ignored in sheets and docs helpers + +`sheets +append`, `sheets +read`, and `docs +write` all hard-coded +`OutputFormat::default()` (JSON) when calling `executor::execute_method`, +meaning `--format table`, `--format yaml`, and `--format csv` had no effect. +The handlers now read the global `--format` flag from `ArgMatches` and pass +it through to the executor, consistent with how `calendar +agenda` and +`gmail +triage` already behave. diff --git a/crates/google-workspace-cli/src/helpers/docs.rs b/crates/google-workspace-cli/src/helpers/docs.rs index d3ef7fa2..93d88f1a 100644 --- a/crates/google-workspace-cli/src/helpers/docs.rs +++ b/crates/google-workspace-cli/src/helpers/docs.rs @@ -68,6 +68,10 @@ TIPS: Box::pin(async move { if let Some(matches) = matches.subcommand_matches("+write") { let (params_str, body_str, scopes) = build_write_request(matches, doc)?; + let output_format = matches + .get_one::("format") + .map(|s| crate::formatter::OutputFormat::from_str(s)) + .unwrap_or_default(); let scope_strs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scope_strs).await { @@ -104,7 +108,7 @@ TIPS: &pagination, None, &crate::helpers::modelarmor::SanitizeMode::Warn, - &crate::formatter::OutputFormat::default(), + &output_format, false, ) .await?; diff --git a/crates/google-workspace-cli/src/helpers/sheets.rs b/crates/google-workspace-cli/src/helpers/sheets.rs index 4357edec..07eb5dfc 100644 --- a/crates/google-workspace-cli/src/helpers/sheets.rs +++ b/crates/google-workspace-cli/src/helpers/sheets.rs @@ -112,6 +112,10 @@ TIPS: if let Some(matches) = matches.subcommand_matches("+append") { let config = parse_append_args(matches); let (params_str, body_str, scopes) = build_append_request(&config, doc)?; + let output_format = matches + .get_one::("format") + .map(|s| crate::formatter::OutputFormat::from_str(s)) + .unwrap_or_default(); let scope_strs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect(); let (token, auth_method) = match auth::get_token(&scope_strs).await { @@ -149,7 +153,7 @@ TIPS: &pagination, None, &crate::helpers::modelarmor::SanitizeMode::Warn, - &crate::formatter::OutputFormat::default(), + &output_format, false, ) .await?; @@ -160,6 +164,10 @@ TIPS: if let Some(matches) = matches.subcommand_matches("+read") { let config = parse_read_args(matches); let (params_str, scopes) = build_read_request(&config, doc)?; + let output_format = matches + .get_one::("format") + .map(|s| crate::formatter::OutputFormat::from_str(s)) + .unwrap_or_default(); // Re-find method let spreadsheets_res = doc.resources.get("spreadsheets").ok_or_else(|| { @@ -192,7 +200,7 @@ TIPS: &executor::PaginationConfig::default(), None, &crate::helpers::modelarmor::SanitizeMode::Warn, - &crate::formatter::OutputFormat::default(), + &output_format, false, ) .await?; From 6dbe0bafb93898977f0286adabeb994b314b5850 Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sun, 5 Apr 2026 21:45:02 -0700 Subject: [PATCH 2/4] fixup: read --format from parent ArgMatches; avoid variable shadowing Rename the subcommand ArgMatches variable from `matches` to `sub_matches` so the outer `matches` is still in scope. Read the global --format flag from the parent matches rather than the subcommand matches, ensuring clap v4 correctly resolves the globally-defined argument. --- crates/google-workspace-cli/src/helpers/docs.rs | 4 ++-- crates/google-workspace-cli/src/helpers/sheets.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/google-workspace-cli/src/helpers/docs.rs b/crates/google-workspace-cli/src/helpers/docs.rs index 93d88f1a..f45668a8 100644 --- a/crates/google-workspace-cli/src/helpers/docs.rs +++ b/crates/google-workspace-cli/src/helpers/docs.rs @@ -66,8 +66,8 @@ TIPS: _sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig, ) -> Pin> + Send + 'a>> { Box::pin(async move { - if let Some(matches) = matches.subcommand_matches("+write") { - let (params_str, body_str, scopes) = build_write_request(matches, doc)?; + if let Some(sub_matches) = matches.subcommand_matches("+write") { + let (params_str, body_str, scopes) = build_write_request(sub_matches, doc)?; let output_format = matches .get_one::("format") .map(|s| crate::formatter::OutputFormat::from_str(s)) diff --git a/crates/google-workspace-cli/src/helpers/sheets.rs b/crates/google-workspace-cli/src/helpers/sheets.rs index 07eb5dfc..2848bf92 100644 --- a/crates/google-workspace-cli/src/helpers/sheets.rs +++ b/crates/google-workspace-cli/src/helpers/sheets.rs @@ -109,8 +109,8 @@ TIPS: _sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig, ) -> Pin> + Send + 'a>> { Box::pin(async move { - if let Some(matches) = matches.subcommand_matches("+append") { - let config = parse_append_args(matches); + if let Some(sub_matches) = matches.subcommand_matches("+append") { + let config = parse_append_args(sub_matches); let (params_str, body_str, scopes) = build_append_request(&config, doc)?; let output_format = matches .get_one::("format") @@ -161,8 +161,8 @@ TIPS: return Ok(true); } - if let Some(matches) = matches.subcommand_matches("+read") { - let config = parse_read_args(matches); + if let Some(sub_matches) = matches.subcommand_matches("+read") { + let config = parse_read_args(sub_matches); let (params_str, scopes) = build_read_request(&config, doc)?; let output_format = matches .get_one::("format") From 563087c9f09dd55a363c35f6f88a235179ebcbfe Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sun, 5 Apr 2026 22:11:18 -0700 Subject: [PATCH 3/4] fixup: revert sub_matches rename; read format and dry-run from subcommand ArgMatches In clap v4, global args propagate to subcommand ArgMatches, so shadowing the outer `matches` with the subcommand result is correct. Reading from the parent matches ignored flags placed after the subcommand (e.g. `gws sheets +append --format table`) and introduced a regression for dry-run lookups. --- crates/google-workspace-cli/src/helpers/docs.rs | 4 ++-- crates/google-workspace-cli/src/helpers/sheets.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/google-workspace-cli/src/helpers/docs.rs b/crates/google-workspace-cli/src/helpers/docs.rs index f45668a8..93d88f1a 100644 --- a/crates/google-workspace-cli/src/helpers/docs.rs +++ b/crates/google-workspace-cli/src/helpers/docs.rs @@ -66,8 +66,8 @@ TIPS: _sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig, ) -> Pin> + Send + 'a>> { Box::pin(async move { - if let Some(sub_matches) = matches.subcommand_matches("+write") { - let (params_str, body_str, scopes) = build_write_request(sub_matches, doc)?; + if let Some(matches) = matches.subcommand_matches("+write") { + let (params_str, body_str, scopes) = build_write_request(matches, doc)?; let output_format = matches .get_one::("format") .map(|s| crate::formatter::OutputFormat::from_str(s)) diff --git a/crates/google-workspace-cli/src/helpers/sheets.rs b/crates/google-workspace-cli/src/helpers/sheets.rs index 2848bf92..07eb5dfc 100644 --- a/crates/google-workspace-cli/src/helpers/sheets.rs +++ b/crates/google-workspace-cli/src/helpers/sheets.rs @@ -109,8 +109,8 @@ TIPS: _sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig, ) -> Pin> + Send + 'a>> { Box::pin(async move { - if let Some(sub_matches) = matches.subcommand_matches("+append") { - let config = parse_append_args(sub_matches); + if let Some(matches) = matches.subcommand_matches("+append") { + let config = parse_append_args(matches); let (params_str, body_str, scopes) = build_append_request(&config, doc)?; let output_format = matches .get_one::("format") @@ -161,8 +161,8 @@ TIPS: return Ok(true); } - if let Some(sub_matches) = matches.subcommand_matches("+read") { - let config = parse_read_args(sub_matches); + if let Some(matches) = matches.subcommand_matches("+read") { + let config = parse_read_args(matches); let (params_str, scopes) = build_read_request(&config, doc)?; let output_format = matches .get_one::("format") From 8334dbf7bd3041fb1fb1258fe8be29664c428ada Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sun, 5 Apr 2026 22:22:22 -0700 Subject: [PATCH 4/4] fixup: use sub_matches for subcommand args; read global flags from parent matches Avoid shadowing the parent `matches` with the subcommand result. Subcommand- specific args (passed to build_write_request, parse_append_args, parse_read_args) use `sub_matches`; global flags `--format` and `--dry-run` are read from the parent `matches` which is where they are defined and reliably present. --- crates/google-workspace-cli/src/helpers/docs.rs | 4 ++-- crates/google-workspace-cli/src/helpers/sheets.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/google-workspace-cli/src/helpers/docs.rs b/crates/google-workspace-cli/src/helpers/docs.rs index 93d88f1a..f45668a8 100644 --- a/crates/google-workspace-cli/src/helpers/docs.rs +++ b/crates/google-workspace-cli/src/helpers/docs.rs @@ -66,8 +66,8 @@ TIPS: _sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig, ) -> Pin> + Send + 'a>> { Box::pin(async move { - if let Some(matches) = matches.subcommand_matches("+write") { - let (params_str, body_str, scopes) = build_write_request(matches, doc)?; + if let Some(sub_matches) = matches.subcommand_matches("+write") { + let (params_str, body_str, scopes) = build_write_request(sub_matches, doc)?; let output_format = matches .get_one::("format") .map(|s| crate::formatter::OutputFormat::from_str(s)) diff --git a/crates/google-workspace-cli/src/helpers/sheets.rs b/crates/google-workspace-cli/src/helpers/sheets.rs index 07eb5dfc..2848bf92 100644 --- a/crates/google-workspace-cli/src/helpers/sheets.rs +++ b/crates/google-workspace-cli/src/helpers/sheets.rs @@ -109,8 +109,8 @@ TIPS: _sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig, ) -> Pin> + Send + 'a>> { Box::pin(async move { - if let Some(matches) = matches.subcommand_matches("+append") { - let config = parse_append_args(matches); + if let Some(sub_matches) = matches.subcommand_matches("+append") { + let config = parse_append_args(sub_matches); let (params_str, body_str, scopes) = build_append_request(&config, doc)?; let output_format = matches .get_one::("format") @@ -161,8 +161,8 @@ TIPS: return Ok(true); } - if let Some(matches) = matches.subcommand_matches("+read") { - let config = parse_read_args(matches); + if let Some(sub_matches) = matches.subcommand_matches("+read") { + let config = parse_read_args(sub_matches); let (params_str, scopes) = build_read_request(&config, doc)?; let output_format = matches .get_one::("format")