feat(executor): stream binary responses to stdout when --output is omitted#750
feat(executor): stream binary responses to stdout when --output is omitted#750hoyt-harness wants to merge 1 commit intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: b2c68f1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Summary of ChangesHello, 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 modifies the CLI's behavior for binary file exports and downloads. Previously, these commands automatically saved content to a local file in the current working directory. The change updates the default behavior to stream raw bytes to stdout, allowing users to pipe output directly to other processes, while maintaining the existing functionality when an explicit --output path is provided. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates binary response handling to stream directly to stdout when an output path is not provided, replacing the previous behavior of defaulting to a local file. It also removes the now-obsolete mime_to_extension helper and refactors some match logic in the script helper. A review comment points out a regression in the new stdout streaming implementation: it fails to respect the capture_output flag and does not track the total number of bytes transferred, which is inconsistent with the file-based output path.
50c5845 to
36bda0c
Compare
|
Good catch — two issues fixed in the latest commit:
Note: I kept the |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies the handling of binary responses to stream directly to stdout when the --output flag is omitted, facilitating easier piping to other processes. It also removes the mime_to_extension helper and refactors some internal logic. Feedback highlights an inconsistency where file operations are still performed when capture_output is enabled, unlike the stdout implementation. Additionally, there is a recommendation to implement a TTY check to prevent streaming raw binary data directly to a terminal, which can cause corruption or security issues.
…itted
Previously handle_binary_response() always wrote content to a
download.{ext} file in cwd and printed a status JSON to stdout, making
it impossible to pipe binary output to another command without an
intermediate file.
Now:
- With --output <path>: content saved to file, status JSON printed
(existing behaviour, unchanged)
- Without --output: raw bytes streamed directly to stdout
This makes drive files export and drive files get --alt media behave
like curl: the content goes to stdout by default, and --output is the
opt-in for file saving.
Also removes mime_to_extension() and its test — the helper existed only
to derive the download.{ext} fallback filename and is now dead code.
Also collapses a pre-existing clippy::collapsible_match in
helpers/script.rs to keep the build warning-clean.
Fixes googleworkspace#743 (sub-issue 4b)
BREAKING CHANGE: scripts that rely on a download.txt / download.pdf
appearing in cwd after drive files export must redirect stdout or add
--output explicitly.
36bda0c to
b2c68f1
Compare
|
Line 397 (TTY guard) — fixed. This is a real gap introduced by the PR: pre-change, binary always went to a file; post-change it can reach a terminal. Added an if !capture_output && std::io::IsTerminal::is_terminal(&std::io::stdout()) {
return Err(GwsError::Validation(
"Refusing to stream binary content to a terminal. \
Use --output <path> to save to a file, or redirect stdout (e.g. '> file')."
.to_string(),
));
}The Line 369 (skip file write when
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies the CLI to stream binary responses directly to stdout when the --output flag is omitted, rather than defaulting to a generated filename. It includes a safety check to prevent binary data from being streamed to a terminal and removes the now-obsolete mime_to_extension helper and its tests. Additionally, the script processing logic was refactored for better readability using match guards. There were no review comments provided, and I have no further feedback to provide.
Summary
drive files export,drive files get --alt media, and any other binary endpoint previously always wrote content to adownload.{ext}file in cwd and printed a status JSON object to stdout, with no way to pipe the content to another command without an intermediate file.This PR changes the default to the Unix/curl convention:
gws drive files export ...download.txtto cwd; prints status JSONgws drive files export ... --output file.txtfile.txt; prints status JSONfile.txt; prints status JSON (unchanged)gws drive files get ... --alt mediadownload.pdfto cwd; prints status JSONgws drive files get ... --alt media --output file.pdffile.pdf; prints status JSONfile.pdf; prints status JSON (unchanged)The
mime_to_extension()helper, which existed only to derive thedownload.{ext}fallback filename, is removed as dead code.Breaking change
Scripts that rely on a
download.txt/download.pdf/ etc. appearing in cwd afterdrive files exportordrive files get --alt mediamust be updated to either:Test plan
gws drive files export --file-id <ID> --params '{"mimeType":"text/plain"}' | headstreams content to stdout without creating any file in cwdgws drive files export --file-id <ID> --params '{"mimeType":"text/plain"}' --output export.txtsavesexport.txtand prints status JSON (existing behaviour)gws drive files get --file-id <ID> --params '{"alt":"media"}' > file.pdfproduces a valid PDFcargo clippy -- -D warningspassescargo testpasses (excluding the two pre-existingauth::tests::test_get_quota_project_*failures that are environment-specific ADC file reads unrelated to this change)Closes #743 (sub-issue 4b)
🤖 Generated with Claude Code