Skip to content

feat(http): add --verbose / -v flag for request/response diagnostics#486

Open
abhiram304 wants to merge 2 commits intogoogleworkspace:mainfrom
abhiram304:feat/verbose-flag
Open

feat(http): add --verbose / -v flag for request/response diagnostics#486
abhiram304 wants to merge 2 commits intogoogleworkspace:mainfrom
abhiram304:feat/verbose-flag

Conversation

@abhiram304
Copy link
Contributor

Summary

  • Adds a global --verbose / -v flag that prints HTTP method, URL, response status, and elapsed time to stderr on every request — stdout remains clean JSON so gws ... | jq pipelines are unaffected
  • Follows the exact same pattern as the existing --dry-run flag: declared global in commands.rs, extracted in main.rs, threaded through execute_method() as verbose: bool
  • For paginated requests, [page N] is emitted to stderr before each page fetch beyond the first
  • Uses only std::time::Instant — no new dependencies

Sample output (--verbose --dry-run):

> GET https://www.googleapis.com/drive/v3/files
< 200 OK (143ms)

Test plan

  • gws drive files list --verbose --dry-run — stderr shows > GET https://..., stdout is the dry-run JSON object
  • gws drive files list --verbose --dry-run 2>/dev/null | jq . — jq receives valid JSON
  • -v short form works identically to --verbose
  • Without the flag, no extra output (default false at all call sites)
  • cargo test commandstest_verbose_arg_present_and_global passes
  • cargo test executor — updated dry-run tests compile and pass

🤖 Generated with Claude Code

@abhiram304 abhiram304 requested a review from jpoehnelt as a code owner March 14, 2026 05:27
@changeset-bot
Copy link

changeset-bot bot commented Mar 14, 2026

🦋 Changeset detected

Latest commit: 33d885b

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 Minor

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 area: http area: core Core CLI parsing, commands, error handling, utilities labels Mar 14, 2026
@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 introduces a new global --verbose flag, or its shorthand -v, to the command-line interface. This enhancement provides users with real-time diagnostic information about HTTP requests and responses, such as the method, URL, status code, and elapsed time, by printing it to stderr. This allows for better debugging and understanding of network interactions without interfering with stdout's machine-readable output, preserving compatibility with command-line piping operations.

Highlights

  • New Verbose Flag: A global --verbose / -v flag has been added to the CLI, enabling detailed HTTP request and response diagnostics.
  • Diagnostic Output: When enabled, the flag prints HTTP method, URL, response status, and elapsed time to stderr for each request.
  • Stdout Integrity: The verbose output is directed to stderr to ensure stdout remains clean and machine-readable, preserving compatibility with piping to tools like jq.
  • Pagination Support: For paginated requests, [page N] indicators are emitted to stderr before each subsequent page fetch.
  • No New Dependencies: The implementation utilizes std::time::Instant and introduces no new external dependencies.
Changelog
  • .changeset/verbose-flag.md
    • Added a new changeset file documenting the addition of the --verbose / -v flag.
  • src/commands.rs
    • Defined the new global --verbose / -v flag using clap.
    • Updated the help text for the --format argument to include tsv.
    • Added a unit test to verify the presence and global scope of the --verbose flag.
  • src/executor.rs
    • Updated the execute_method function signature to accept a verbose boolean parameter.
    • Added documentation clarifying the contract for stdout and stderr usage.
    • Implemented conditional eprintln! statements to output request details (method, URL) and response details (status, elapsed time) to stderr when verbose is true.
    • Added eprintln! for pagination progress when verbose is true.
    • Modified existing test calls to execute_method to pass false for the new verbose parameter.
  • src/helpers/calendar.rs
    • Updated the call to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/helpers/chat.rs
    • Updated the call to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/helpers/docs.rs
    • Updated the call to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/helpers/drive.rs
    • Updated the call to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/helpers/gmail/mod.rs
    • Updated the call to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/helpers/script.rs
    • Updated the call to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/helpers/sheets.rs
    • Updated two calls to executor::execute_method to include the new verbose parameter, setting it to false.
  • src/main.rs
    • Extracted the verbose flag value from matched_args.
    • Passed the verbose flag to the execute_method function.
    • Updated the warning message for unknown output formats to include tsv.
    • Added --verbose / -v to the print_usage help output.
Activity
  • The pull request was created by abhiram304.
  • No human comments or reviews have been recorded yet.
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 introduces a new global --verbose (-v) flag to the CLI, enabling detailed logging of HTTP requests and responses (method, URL, status, timing) to stderr for debugging purposes. It also updates the --format option to include tsv as a valid output format. The changes include adding the flag definition, modifying the execute_method signature to accept the verbose flag, and implementing the conditional logging logic. Review comments highlight that the verbose output for request URLs is incomplete, as it currently omits query parameters and pageToken for paginated requests, which could be misleading. Additionally, several helper commands (calendar, chat, docs, drive, gmail, script, sheets) hardcode the verbose argument to false when calling execute_method, preventing the global --verbose flag from functioning correctly within these contexts.

Adds a global --verbose / -v flag that prints HTTP request and response
details to stderr without touching stdout, keeping pipe-friendly output
intact. When enabled:

  > GET https://www.googleapis.com/drive/v3/files
  < 200 OK (143ms)
  [page 2]   ← emitted at the start of each additional page fetch

Implementation:
- commands.rs: declare --verbose as a global SetTrue arg (mirrors --dry-run)
- executor.rs: add verbose: bool parameter to execute_method(); log method
  + URL before send(), status + elapsed after; log [page N] at top of loop
  for pages > 1. Also adds stdout/stderr contract doc comment.
- main.rs: extract get_flag("verbose") and thread it through
- All 8 helper execute_method() call sites: pass false (helpers have no
  --verbose wiring yet; callers that want it can opt in later)
@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 introduces a valuable --verbose flag for HTTP request diagnostics, which will greatly aid in debugging. The implementation is well-structured, following existing patterns in the codebase, and includes appropriate tests. I've identified two high-severity issues. One is a correctness issue where the URL printed in verbose mode is not properly encoded, which could be misleading. The other is that the help text for the --format option has been updated to include tsv, but this format is not actually implemented, which will confuse users and is also out of scope for this PR, violating the rule against scope creep. My review provides specific suggestions to address these points.

Address review feedback:
- Use url::form_urlencoded for proper percent-encoding of query params
  in verbose diagnostic output, matching what reqwest actually sends
- Revert --format help text to "json, table, yaml, csv" — tsv mention
  was out of scope for this PR (tracked separately in feat/add-tsv-format)
- Add `url` as an explicit dependency (was previously transitive-only)
@googleworkspace-bot
Copy link
Collaborator

/gemini review

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 introduces a --verbose / -v flag for HTTP request/response diagnostics, which is a great feature for debugging. The implementation correctly adds the global flag and passes it down to the executor. The new logging in executor.rs provides useful information to stderr. However, I've identified a high-severity issue with code duplication: the logic to construct the URL for logging duplicates the query parameter assembly logic from build_http_request. This could lead to inconsistencies in the future. My review includes a comment with a suggestion for refactoring to improve maintainability.

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 area: distribution area: http

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants