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..f45668a8 100644 --- a/crates/google-workspace-cli/src/helpers/docs.rs +++ b/crates/google-workspace-cli/src/helpers/docs.rs @@ -66,8 +66,12 @@ 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)) + .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..2848bf92 100644 --- a/crates/google-workspace-cli/src/helpers/sheets.rs +++ b/crates/google-workspace-cli/src/helpers/sheets.rs @@ -109,9 +109,13 @@ 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") + .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?; @@ -157,9 +161,13 @@ 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") + .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?;