Skip to content

refactor: replace manual arg parsing in auth commands with clap#594

Merged
jpoehnelt merged 5 commits intomainfrom
fix/auth-clap
Mar 23, 2026
Merged

refactor: replace manual arg parsing in auth commands with clap#594
jpoehnelt merged 5 commits intomainfrom
fix/auth-clap

Conversation

@jpoehnelt
Copy link
Copy Markdown
Member

Summary

Replace manual argument parsing in all gws auth subcommands with structured clap::Command definitions.

Changes

  • ScopeMode enum — replaces raw arg passing to resolve_scopes, making scope selection type-safe (Default, Readonly, Full, Custom(Vec<String>))
  • auth_command() — clap Command with subcommands: login, setup, status, export, logout
  • handle_auth_command — replaced hardcoded USAGE string + manual --help check + match args[0] dispatch with clap subcommand routing
  • handle_loginhandle_login_inner — eliminated two-pass manual parsing (services extraction loop + scopes/readonly/full flag scanning) with single clap parse
  • resolve_scopes — now accepts ScopeMode instead of raw &[String] args
  • export --unmasked — handled via clap flag instead of manual args[1] == "--unmasked" check
  • run_login(&[]) — public API preserved for setup.rs compatibility

Benefits

  • All auth subcommands now have proper --help support
  • Unknown flags are rejected with informative errors (previously silently ignored)
  • Help text stays synchronized with defined arguments
  • --help exits cleanly (code 0), invalid flags return non-zero

Tests

All 63 existing tests updated and passing.

- Add ScopeMode enum (Default, Readonly, Full, Custom) for type-safe
  scope selection
- Build auth_command() with clap subcommands: login, setup, status,
  export, logout
- Replace manual --help check and match dispatch in handle_auth_command
  with clap subcommand routing
- Replace two-pass manual parsing in handle_login (services extraction)
  and resolve_scopes (scopes/readonly/full flags) with single clap parse
- Add --unmasked flag to export subcommand via clap
- Preserve run_login(&[]) public API for setup.rs compatibility
- Update all 63 tests to use ScopeMode-based API
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

🦋 Changeset detected

Latest commit: b6fe1a9

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

@gemini-code-assist
Copy link
Copy Markdown
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 significantly improves the command-line interface for gws auth subcommands by migrating from manual argument parsing to the robust clap library. This refactoring enhances user experience with standardized help messages, better error handling for invalid arguments, and more predictable behavior. The change also introduces a ScopeMode enum for type-safe scope management, simplifying the internal logic for authentication flows.

Highlights

  • Argument Parsing Refactor: Replaced manual argument parsing in gws auth subcommands with the clap crate for structured command-line interface definitions.
  • ScopeMode Enum Introduction: Introduced a ScopeMode enum (Default, Readonly, Full, Custom) to provide type-safe handling of scope selection, replacing raw string argument passing.
  • Enhanced CLI Experience: Implemented proper --help support, informative error messages for unknown flags, and synchronized help text across all auth subcommands.
  • Simplified Login Logic: Refactored handle_login into handle_login_inner to accept pre-parsed ScopeMode and service filters, eliminating complex manual argument extraction.
  • Updated Scope Resolution: Modified resolve_scopes to directly utilize the new ScopeMode enum, streamlining the logic for determining authentication scopes.
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.

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.

@googleworkspace-bot googleworkspace-bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 23, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 67.85714% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.00%. Comparing base (d341de2) to head (b6fe1a9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/auth_commands.rs 67.85% 54 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #594      +/-   ##
==========================================
- Coverage   69.02%   69.00%   -0.03%     
==========================================
  Files          42       42              
  Lines       19311    19371      +60     
==========================================
+ Hits        13330    13367      +37     
- Misses       5981     6004      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
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 is a great refactoring that replaces manual argument parsing with clap, significantly improving the robustness and maintainability of the gws auth subcommands. The introduction of the ScopeMode enum is a particularly nice touch for type safety.

I've identified a couple of areas for improvement related to code duplication and performance in the new clap integration. My comments provide suggestions to address these points by extracting duplicated logic into a helper function and using once_cell for efficient command initialization.

Overall, this is a high-quality change that modernizes the command-line handling. Well done.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
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 is a great refactoring that replaces manual argument parsing with clap, improving robustness, maintainability, and user experience. The introduction of the ScopeMode enum is a good move for type safety. The changes are well-structured and the backward compatibility for setup commands is thoughtfully handled. I have one suggestion to make the command-line interface for gws auth login even more robust by making scope-related flags mutually exclusive.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
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 is a great refactoring that replaces manual argument parsing with clap for the gws auth subcommands. This significantly improves the robustness, maintainability, and user-friendliness of the CLI by providing proper help messages, error handling for unknown flags, and type-safe argument parsing via the new ScopeMode enum. The changes are well-structured, and the test suite has been updated accordingly.

I have one suggestion to improve the robustness of custom scope parsing.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
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 is a significant and well-executed refactoring that replaces manual argument parsing for auth commands with clap. The introduction of the ScopeMode enum and the clear separation of parsing logic greatly improve the code's robustness and maintainability. My review found one critical issue related to a potential runtime panic due to a fragile coupling between command definitions. Addressing this will make the implementation fully robust.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@github-actions github-actions bot removed the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
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 is a well-executed refactoring that replaces manual argument parsing with clap for the gws auth subcommands. The changes significantly improve code clarity, maintainability, and user experience by providing proper help messages and argument validation. The introduction of the ScopeMode enum is a great improvement for type safety. I have one suggestion regarding duplicated code for clap error handling that could further enhance maintainability.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 23, 2026
@jpoehnelt jpoehnelt merged commit a078945 into main Mar 23, 2026
32 of 34 checks passed
@jpoehnelt jpoehnelt deleted the fix/auth-clap branch March 23, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth cla: yes This human has signed the Contributor License Agreement. gemini: reviewed Gemini Code Assist has reviewed the latest changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants