Skip to content

fix: gws auth setup --help prints usage instead of running wizard#442

Open
anshul-garg27 wants to merge 1 commit intogoogleworkspace:mainfrom
anshul-garg27:fix/auth-setup-help-flag
Open

fix: gws auth setup --help prints usage instead of running wizard#442
anshul-garg27 wants to merge 1 commit intogoogleworkspace:mainfrom
anshul-garg27:fix/auth-setup-help-flag

Conversation

@anshul-garg27
Copy link
Contributor

Summary

  • gws auth setup --help (and -h) now prints a usage message and exits cleanly
  • Previously it would start the setup wizard and fail with a gcloud-not-found error on machines without gcloud installed

Root cause

run_setup() in src/setup.rs parsed arguments but never checked for --help/-h, so the wizard always started. The help flag was silently ignored by parse_setup_args.

Fix

Added an early-return at the top of run_setup() that checks for --help/-h before any side effects (gcloud checks, TUI wizard, etc.).

Test plan

  • run_setup(&["--help"]) returns Ok(()) without starting wizard
  • run_setup(&["-h"]) returns Ok(())
  • run_setup(&["--project", "my-proj", "--help"]) returns Ok(()) (help takes priority)
  • Existing tests continue to pass

Closes #280

Previously, `gws auth setup --help` would start the setup wizard
(and fail if gcloud was not installed). Now it early-returns with
a usage message before any side effects.

Adds tests to verify --help, -h, and --help combined with other
flags all return Ok without starting the wizard.
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 6121656

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

@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 resolves an issue where the gws auth setup --help command would incorrectly launch the setup wizard, potentially causing errors if gcloud was not present. The change ensures that invoking the help flag now immediately displays the command's usage information and exits cleanly, significantly improving the command-line experience for users seeking assistance.

Highlights

  • Help command behavior: The gws auth setup --help and -h commands now correctly print a usage message and exit, rather than initiating the setup wizard.
  • Root cause addressed: The previous behavior was due to run_setup() not checking for help flags before starting the wizard, leading to failures if gcloud was not installed.
  • Implementation: An early-return check for --help or -h was added at the beginning of the run_setup() function to prioritize displaying help.
Changelog
  • .changeset/fix-auth-setup-help.md
    • Added a new changeset file.
  • src/setup.rs
    • Implemented an early-return check for --help and -h arguments in run_setup to display usage information.
    • Added new unit tests to verify the correct behavior of the help flags, including scenarios with other arguments.
Activity
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 the --help and -h flags for the gws auth setup command, preventing the setup wizard from running unintentionally. The change includes an early return in run_setup and adds corresponding tests to verify the new behavior. My feedback includes a suggestion to improve the maintainability of the new help message by extracting it into a constant.

Comment on lines +1602 to +1614
if args.iter().any(|a| a == "--help" || a == "-h") {
println!(
"Usage: gws auth setup [options]\n\n\
Configure a GCP project, enable Workspace APIs, and create OAuth\n\
credentials — all in one guided wizard.\n\n\
Options:\n\
\x20 --project <ID> Use an existing GCP project instead of creating one\n\
\x20 --dry-run Show what would be done without making changes\n\
\x20 --login Run `gws auth login` after successful setup\n\
\x20 -h, --help Show this help message"
);
return Ok(());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

For better maintainability and readability, it's a good practice to extract string literals, especially multi-line ones, into constants. This makes the help text easier to find and modify without digging into the logic. While a module-level const would be ideal, defining it inside the if block is still a good improvement that can be applied within the scope of this diff.

    if args.iter().any(|a| a == "--help" || a == "-h") {
        const SETUP_USAGE: &str = "Usage: gws auth setup [options]\n\n\
             Configure a GCP project, enable Workspace APIs, and create OAuth\n\
             credentials — all in one guided wizard.\n\n\
             Options:\n\
             \x20 --project <ID>  Use an existing GCP project instead of creating one\n\
             \x20 --dry-run       Show what would be done without making changes\n\
             \x20 --login         Run `gws auth login` after successful setup\n\
             \x20 -h, --help      Show this help message";
        println!("{SETUP_USAGE}");
        return Ok(());
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, but keeping the string inline here for simplicity — this is a small, self-contained usage block (8 lines) in a single function. Extracting it to a constant would add indirection without much benefit at this scale. Happy to refactor if the maintainer prefers it.

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

Projects

None yet

2 participants