Skip to content

feat: Add shell completion support (bash, zsh, fish, powershell, elvish)#501

Open
dumko2001 wants to merge 5 commits intogoogleworkspace:mainfrom
dumko2001:feature/issue-323-shell-completion
Open

feat: Add shell completion support (bash, zsh, fish, powershell, elvish)#501
dumko2001 wants to merge 5 commits intogoogleworkspace:mainfrom
dumko2001:feature/issue-323-shell-completion

Conversation

@dumko2001
Copy link

@dumko2001 dumko2001 commented Mar 15, 2026

Description

This PR adds shell completion support for major shells (bash, zsh, fish, powershell, elvish) using a bridge approach with a hidden __complete command. This enables dynamic completion for subcommands and flags based on the Discovery Document for each service.

Fixes #323

Dry Run Output:

{
  "method": "get",
  "params": {
    "fileId": "123"
  },
  "scopes": ["https://www.googleapis.com/auth/drive.readonly"]
}

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

@dumko2001 dumko2001 requested a review from jpoehnelt as a code owner March 15, 2026 17:27
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

🦋 Changeset detected

Latest commit: 4b53399

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: distribution area: tui area: core Core CLI parsing, commands, error handling, utilities labels Mar 15, 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 significantly enhances the command-line interface by introducing robust shell completion capabilities. Users can now generate shell-specific scripts to enable dynamic suggestions for commands, subcommands, and flags, greatly improving usability and discoverability. The implementation uses a bridge approach, allowing the CLI to provide context-aware completions across various popular shells.

Highlights

  • Shell Completion Support: Added comprehensive shell completion for bash, zsh, fish, powershell, and elvish, accessible via gws completion <shell>.
  • Dynamic Completion Logic: Implemented dynamic completion that provides suggestions for subcommands and flags, including prefix filtering and descriptions.
  • Dependency Management: Updated Cargo.toml and Cargo.lock to include the clap_complete crate and adjusted other dependencies, notably downgrading ratatui.
  • New Module for Completion: Introduced a new src/completion.rs module to encapsulate all shell completion related logic.
Changelog
  • .changeset/feat-shell-completion.md
    • Added a new changeset entry for shell completion support.
  • Cargo.lock
    • Updated various dependency versions.
    • Removed several unused dependencies.
    • Added clap_complete and cassowary dependencies.
  • Cargo.toml
    • Added rust-version specification.
    • Introduced clap_complete dependency.
    • Downgraded ratatui dependency.
  • src/completion.rs
    • Implemented print_bridge_script function to generate shell-specific completion scripts.
    • Developed handle_dynamic_completion for recursive subcommand and flag completion.
    • Created handle_complete_command to manage dynamic completion requests.
    • Included unit tests for dynamic completion logic.
  • src/main.rs
    • Imported the new completion module.
    • Integrated completion and __complete command handling into the main run function.
    • Introduced build_static_cli function to construct the base CLI command for completion.
  • src/setup_tui.rs
    • Added Stylize trait import from ratatui::prelude.
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 shell completion support for various shells, which is a great feature for usability. The implementation uses a bridge script approach with a hidden __complete command, which is a solid pattern for dynamic CLIs. I've found one high-severity issue with the argument parsing for the new completion command, which can lead to incorrect behavior or panics when flags like --help are used. My suggestion addresses this by using the existing clap parser, making the implementation more robust and consistent.

@dumko2001
Copy link
Author

Thanks for the suggestion! I've refactored the completion command parsing to use the existing build_static_cli() with clap, which handles --help and validation correctly. Pushed the update now.

@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 shell completion support for various shells, which is a great feature. The implementation uses a bridge script and a hidden __complete command to provide dynamic completions, which is a solid approach. The new completion.rs module is well-structured, and the integration into main.rs with the build_static_cli refactoring is clean.

I have two main points of feedback:

  1. In src/completion.rs, there's a hardcoded list of static commands that creates a maintenance burden. I've suggested a more dynamic approach to avoid this.
  2. The PR also includes a downgrade of the ratatui dependency from version 0.30.0 to 0.29.0. This is a significant change that seems unrelated to shell completion and should ideally be in a separate pull request to avoid scope creep.

Overall, the core feature is well-implemented. Addressing these points will improve the long-term maintainability of the code.

@dumko2001
Copy link
Author

I've refactored the static command detection in completion.rs as suggested. It now dynamically identifies subcommands of the static CLI that aren't service aliases, making it much more maintainable.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

@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 shell completion support for various shells, a valuable feature for the CLI. The implementation uses a bridge command __complete to dynamically generate completions, which is a suitable approach for a CLI with a dynamic command surface. My review identified a critical issue in the argument parsing logic within the completion handler. The current implementation does not correctly handle flags that take values, causing completions to fail in common scenarios. I have provided a detailed comment and a code suggestion to address this bug.

@dumko2001
Copy link
Author

Excellent catch! I've updated the argument parsing logic to correctly identify flags that take values and consume them. This ensures that commands like gws drive --api-version v3 files provide the correct completions for the files resource. Added a unit test to cover this case as well.

@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 shell completion support, which is a valuable feature for the CLI. The implementation uses a bridge command (__complete) to handle dynamic completions, a suitable approach for this tool. However, the argument parsing logic within the completion handler has a critical flaw: it doesn't correctly process flags that take values. This leads to incorrect completion suggestions in many common scenarios. I've provided a detailed comment with a suggested fix to improve the robustness of the argument parsing.

@dumko2001
Copy link
Author

I've implemented the more robust flag parsing logic as suggested. The completer now correctly identifies flags using their clap definitions and determines whether to consume the next argument as a value based on the ArgAction. I've also added tests for both --key value and --key=value syntaxes.

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 shell completion support for various shells by adding a completion command and a hidden __complete command for dynamic completion generation. The implementation uses a bridge script approach, which is a solid pattern. The code is well-structured, with the core logic encapsulated in a new completion module. My main feedback concerns the argument parsing logic within the dynamic completer, which does not correctly handle combined short flags (e.g., -ab), a standard CLI feature. This can lead to incorrect completions. I've left a specific comment with details on this issue.

@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 shell completion support for various shells, which is a great enhancement for the CLI's usability. My review identified two critical compilation errors in src/main.rs related to incorrect value ownership of the args vector, which will prevent the code from building. Additionally, the new tests for the completion logic in src/completion.rs are currently ineffective as they don't assert on the output, failing to verify the correctness of the generated completions. Addressing these points will ensure the new feature is robust and correct.

@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 shell completion support for various shells, which is a great feature for improving the CLI's usability. The implementation uses a bridge approach with a hidden __complete command to provide dynamic completions. While the overall approach is solid, I've found a critical issue in the completion logic that prevents it from correctly providing suggestions for flag values. The provided feedback includes a fix for this issue to ensure the new feature works as expected.

This PR adds shell completion support for major shells using a bridge approach with a hidden __complete command. This enables dynamic completion for subcommands and flags based on the Discovery Document for each service.

Fixes googleworkspace#323
@dumko2001 dumko2001 force-pushed the feature/issue-323-shell-completion branch from e664395 to 150f5f2 Compare March 16, 2026 10:45
@dumko2001
Copy link
Author

I have addressed all the feedback from the reviews.
Specifically:

  • Refactored completion logic into to enable effective unit testing with assertions.
  • Fixed the flag value detection bug and added support for combined short flags (e.g., ).
  • Resolved ownership issues in .
  • Removed unrelated addition in .
  • Squashed the history into a single, clean commit.

All tests and clippy checks are passing.

@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 shell completion support for various shells using a bridge script that calls a hidden __complete command. This is a solid approach for providing dynamic completions based on the API discovery documents. The implementation includes completion logic for subcommands, flags, and flag values. I've found one critical bug in the completion logic where it fails to provide value suggestions for a flag when it's the last argument on the command line. The fix is straightforward and I've provided a suggestion.

@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 shell completion support for bash, zsh, fish, PowerShell, and elvish. The implementation uses a hidden __complete command to dynamically generate completions. The overall approach is solid, but the PowerShell completion script is fundamentally flawed and will not work correctly for commands with quoted arguments containing spaces. This has been flagged as a critical issue that needs to be addressed for the feature to be considered functional on PowerShell.

@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 shell completion support for various shells, which is a significant usability improvement. The implementation uses a bridge command __complete to handle dynamic completions, a robust approach for a CLI that interacts with multiple APIs. The code is well-structured and includes tests for the new completion logic. I've identified one high-severity issue in the generated bash completion script that could lead to incorrect behavior for completion items containing spaces. The fix is provided as a code suggestion.

@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 shell completion support for bash, zsh, fish, powershell, and elvish. It uses a hidden __complete command to dynamically generate completions for both static and service-based subcommands and flags. The implementation is comprehensive and includes new tests. My review found one area for improvement in the completion logic to remove some unreachable code, which will improve maintainability.

@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 shell completion support for various shells, which is a great feature for improving the CLI's usability. The implementation uses a bridge approach with a hidden __complete command to provide dynamic completions for both static commands and dynamic, service-based commands. The core logic for parsing arguments and generating completions is comprehensive, and the addition of tests is appreciated.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add shell completion support (bash, zsh, fish)

2 participants