Skip to content

feat(pm): add shell completion generation via utoo completions <shell> - #2601

Merged
elrrrrrrr merged 2 commits into
utooland:nextfrom
killagu-claw:next
Feb 18, 2026
Merged

feat(pm): add shell completion generation via utoo completions <shell>#2601
elrrrrrrr merged 2 commits into
utooland:nextfrom
killagu-claw:next

Conversation

@killagu-claw

Copy link
Copy Markdown
Contributor

Adds a new utoo completions <shell> command to generate shell completion scripts.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @killagu-claw, 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 utoo command-line tool by integrating a new feature for generating shell completion scripts. This addition significantly improves the user experience by providing auto-completion capabilities for utoo commands in various shell environments, making the CLI more user-friendly and efficient.

Highlights

  • New Feature: Shell Completion Generation: Introduced a new utoo completions <shell> command that allows users to generate shell completion scripts for various shells (e.g., Bash, Zsh, Fish, PowerShell, Elvish).
  • Dependency Addition: Added the clap_complete crate as a new dependency to enable the generation of shell completion scripts.
  • Command Line Interface Extension: Extended the utoo CLI with a new subcommand completions and its associated logic to handle the generation process.
Changelog
  • Cargo.lock
    • Added clap_complete package entry with its version and checksum.
    • Included clap_complete in the pm package's dependencies.
  • crates/pm/Cargo.toml
    • Declared clap_complete as a new dependency with version 4.
  • crates/pm/src/constants.rs
    • Introduced COMPLETIONS_NAME and COMPLETIONS_ABOUT constants for the new command.
  • crates/pm/src/main.rs
    • Imported CommandFactory from clap.
    • Included new COMPLETIONS_ABOUT and COMPLETIONS_NAME constants.
    • Defined the Completions enum variant within Commands to represent the new subcommand, accepting a clap_complete::Shell argument.
    • Implemented the Completions command logic to call clap_complete::generate for script output.
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 Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 completions command to generate shell completion scripts, which is a great enhancement for usability. The implementation correctly uses the clap_complete crate. My review includes one suggestion to run the synchronous completion generation within a tokio::task::spawn_blocking call. This is a best practice in asynchronous Rust to prevent blocking the async runtime, ensuring the application remains responsive.

Comment thread crates/pm/src/main.rs Outdated
Uses clap_complete to generate completion scripts for bash, zsh, fish, elvish, and powershell.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread crates/pm/src/constants.rs Outdated
pub const INIT_ABOUT: &str = "Create a package.json file";

pub const COMPLETIONS_NAME: &str = "completions";
pub const COMPLETIONS_ABOUT: &str = "Generate shell completion scripts";

@elrrrrrrr elrrrrrrr Feb 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

类似 registry 配置,可以考虑在 utoo --help 的默认文档里添加 completion 的使用提示

  Add to your shell config:
    bash:  echo 'eval "$(utoo completions bash)"' >> ~/.bashrc
    zsh:   echo 'eval "$(utoo completions zsh)"' >> ~/.zshrc
    fish:  utoo completions fish > ~/.config/fish/completions/utoo.fish

如果用户已经配置过了,就不用提示

Comment thread crates/pm/src/main.rs Outdated
#[command(name = COMPLETIONS_NAME, about = COMPLETIONS_ABOUT)]
Completions {
/// Shell to generate completions for
shell: clap_complete::Shell,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Completions {
/// Shell to generate completions for (auto-detected if omitted)
shell: Option<clap_complete::Shell>,
},

改成从 $SHELL 内直接获取?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let shell = shell
      .or_else(|| std::env::var("SHELL").ok().and_then(|s| {
          match s.rsplit('/').next()? {
              "bash" => Some(clap_complete::Shell::Bash),
              "zsh" => Some(clap_complete::Shell::Zsh),
              "fish" => Some(clap_complete::Shell::Fish),
              _ => None,
          }
      }));

  match shell {
      Some(shell) => {
          clap_complete::generate(shell, &mut Cli::command(), APP_NAME, &mut std::io::stdout());
      }
      None => {
          eprintln!("Could not detect shell. Usage: utoo completions <bash|zsh|fish|powershell|elvish>");
      }
  }

这样大多数场景直接 utoo completions 就行,不用记参数。
检测不到时给明确提示。PowerShell 和 Elvish 用户本来就少,让他们手动指定没问题。

@elrrrrrrr

Copy link
Copy Markdown
Contributor

@killagu-claw 你是一个经验丰富、能力超群的 rust 开发工程师
功能实现还需要考虑到易用性、请根据评论进行修改,相信你一定可以的 💪🏻

- auto-detect shell from /bin/zsh when omitted
- run generation in spawn_blocking to avoid blocking tokio runtime
- add help text with common shell setup hints
@elrrrrrrr
elrrrrrrr merged commit 61d10e2 into utooland:next Feb 18, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants