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
12 changes: 12 additions & 0 deletions .changeset/helpers-respect-format-flag.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 7 additions & 3 deletions crates/google-workspace-cli/src/helpers/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ TIPS:
_sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig,
) -> Pin<Box<dyn Future<Output = Result<bool, GwsError>> + 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::<String>("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 {
Expand Down Expand Up @@ -104,7 +108,7 @@ TIPS:
&pagination,
None,
&crate::helpers::modelarmor::SanitizeMode::Warn,
&crate::formatter::OutputFormat::default(),
&output_format,
false,
)
.await?;
Expand Down
20 changes: 14 additions & 6 deletions crates/google-workspace-cli/src/helpers/sheets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ TIPS:
_sanitize_config: &'a crate::helpers::modelarmor::SanitizeConfig,
) -> Pin<Box<dyn Future<Output = Result<bool, GwsError>> + 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::<String>("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 {
Expand Down Expand Up @@ -149,17 +153,21 @@ TIPS:
&pagination,
None,
&crate::helpers::modelarmor::SanitizeMode::Warn,
&crate::formatter::OutputFormat::default(),
&output_format,
false,
)
.await?;

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::<String>("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(|| {
Expand Down Expand Up @@ -192,7 +200,7 @@ TIPS:
&executor::PaginationConfig::default(),
None,
&crate::helpers::modelarmor::SanitizeMode::Warn,
&crate::formatter::OutputFormat::default(),
&output_format,
false,
)
.await?;
Expand Down
Loading