Skip to content

fix: handle array-of-arrays in CSV formatter#288

Open
drassi wants to merge 1 commit intogoogleworkspace:mainfrom
drassi:fix/csv-array-of-arrays
Open

fix: handle array-of-arrays in CSV formatter#288
drassi wants to merge 1 commit intogoogleworkspace:mainfrom
drassi:fix/csv-array-of-arrays

Conversation

@drassi
Copy link

@drassi drassi commented Mar 7, 2026

Summary

  • --format csv now correctly handles array-of-arrays responses (e.g. Sheets values API)
  • Adds early return path for non-object arrays, mirroring the table formatter's existing handling
  • Includes changeset

Fixes #283

Test plan

  • New unit test test_format_csv_array_of_arrays covering the Sheets-style response shape
  • Existing CSV tests still pass (object-based responses unaffected)
  • Verified end-to-end against public sample spreadsheet
  • cargo fmt, cargo clippy -- -D warnings, cargo test all pass

The CSV formatter assumed all items were JSON objects when collecting
column names. APIs that return arrays of arrays (e.g. Sheets values)
produced empty newlines instead of data.

Add an early return path for non-object arrays that emits each inner
array's elements as CSV cells directly, mirroring the table formatter's
existing "array of non-objects" handling.

Fixes googleworkspace#283

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2026

🦋 Changeset detected

Latest commit: 923d89a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 7, 2026
@google-cla
Copy link

google-cla bot commented Mar 7, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the CSV output formatter to accurately handle nested array structures, particularly those encountered when interacting with APIs like Google Sheets. This ensures that data represented as an array of arrays is correctly serialized into a CSV format, improving the robustness and compatibility of the CLI's output capabilities.

Highlights

  • CSV Formatting Improvement: The --format csv option now correctly processes responses that are arrays of arrays, such as those returned by the Google Sheets values API.
  • Early Return Path: An early return path was introduced in the CSV formatter to handle non-object arrays, aligning its behavior with the existing table formatter.
  • New Unit Test: A dedicated unit test, test_format_csv_array_of_arrays, was added to specifically cover the Sheets-style array-of-arrays response shape.
Changelog
  • .changeset/fix-csv-array-of-arrays.md
    • Added a changeset entry detailing the fix for CSV array-of-arrays handling.
  • src/formatter.rs
    • Implemented new logic in format_csv_page to correctly process arrays containing other arrays.
    • Added a new unit test test_format_csv_array_of_arrays to validate the updated CSV formatting for nested arrays.
Activity
  • Added a new unit test test_format_csv_array_of_arrays to cover the specific array-of-arrays scenario.
  • Confirmed that all existing CSV tests continue to pass, ensuring no regressions for object-based responses.
  • Performed end-to-end verification against a public sample Google Spreadsheet to confirm the fix.
  • Ensured code quality by running cargo fmt, cargo clippy -- -D warnings, and cargo test.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements CSV formatting for array-of-arrays responses, such as those from the Google Sheets API. A new code path is added to handle arrays of non-objects, treating inner arrays as rows, which is a significant improvement over the previous behavior. The changes are well-tested with a new unit test covering the Sheets-style response. The implementation is clean and effectively addresses the issue.

@drassi
Copy link
Author

drassi commented Mar 7, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

I signed the CLA prior to opening this PR, looks like it did get recognized for me, but bot's not happy with the Claude co-author mention. I had thought the co-author note was OK to leave in there after seeing it on a bunch of other external commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--format csv outputs empty rows for Sheets values API

2 participants