fix: handle --help flag in gws auth setup#303
fix: handle --help flag in gws auth setup#303zerone0x wants to merge 2 commits intogoogleworkspace:mainfrom
Conversation
The +triage helper uses the `q` query parameter when listing messages, but Gmail's metadata scope does not support `q` and returns 403. When a user's OAuth token includes both gmail.metadata and gmail.modify scopes, the API may resolve to the metadata code path and reject the query. Switch +triage from gmail.modify to gmail.readonly, which is the minimum scope that supports query filtering and aligns with the read-only nature of the triage command. Fixes googleworkspace#265 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When `gws auth setup --help` is invoked on a machine without gcloud, the command errors instead of printing help. This adds an early check for -h/--help that prints usage info and exits before any setup logic. Fixes googleworkspace#280 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: d51e780 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 |
|
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. |
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 enhances the Highlights
Changelog
Activity
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. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces two main changes. First, it adds handling for the --help and -h flags to the gws auth setup command, ensuring that the help message is displayed without running any pre-checks like gcloud availability. Second, it corrects the authentication scope for the gmail +triage command from gmail.modify to gmail.readonly to fix a 403 error.
My review identifies a correctness issue in the implementation of the help flag handling. The current approach can misinterpret command-line arguments, treating values for options as help flags. I've provided a suggestion to create a more robust argument parser that correctly distinguishes between flags and values.
| fn is_help_requested(args: &[String]) -> bool { | ||
| args.iter().any(|arg| arg == "--help" || arg == "-h") | ||
| } | ||
|
|
||
| /// Run the full setup flow. Orchestrates all steps and outputs JSON summary. | ||
| pub async fn run_setup(args: &[String]) -> Result<(), GwsError> { | ||
| if is_help_requested(args) { | ||
| println!("{SETUP_USAGE}"); | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let opts = parse_setup_args(args); |
There was a problem hiding this comment.
The current implementation with a separate is_help_requested function is too simplistic and can lead to incorrect behavior. For example, a command like gws auth setup --project -h would be misinterpreted as a request for help, when the user likely intends to set the project ID to "-h". The is_help_requested function doesn't consider the argument's context.
To fix this, the argument parsing logic should be consolidated. Instead of a separate help check, the main argument parser should also handle the help flags. This ensures that option values are not mistaken for flags.
I suggest replacing both is_help_requested and the call to parse_setup_args with a single, more robust parsing loop at the beginning of run_setup.
let mut project = None;
let mut dry_run = false;
let mut i = 0;
while i < args.len() {
match args[i].as_str() {
"--help" | "-h" => {
println!("{SETUP_USAGE}");
return Ok(());
}
"--project" => {
if i + 1 < args.len() {
project = Some(args[i + 1].clone());
i += 2;
} else {
i += 1; // Or return an error for missing value
}
}
s if s.starts_with("--project=") => {
project = Some(s.split_once('=').unwrap().1.to_string());
i += 1;
}
"--dry-run" => {
dry_run = true;
i += 1;
}
_ => {
i += 1;
}
}
}
let opts = SetupOptions { project, dry_run };
Summary
-h/--helpdetection inrun_setup()that prints usage and returns before any gcloud or setup checks rungws auth setup --helpfrom failing with a gcloud-not-found error on machines without gcloud installedis_help_requestedhelperFixes #280
Test plan
cargo test -- setuppasses (92 tests including 3 new ones)cargo clippy -- -D warningscleangws auth setup --helpprints usage and exits 0gws auth setup --helpdoes not require gcloud🤖 Generated with Claude Code