feat(pm): add shell completion generation via utoo completions <shell> - #2601
Conversation
Summary of ChangesHello @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 Highlights
Changelog
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 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.
Uses clap_complete to generate completion scripts for bash, zsh, fish, elvish, and powershell. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| 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"; |
There was a problem hiding this comment.
类似 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
如果用户已经配置过了,就不用提示
| #[command(name = COMPLETIONS_NAME, about = COMPLETIONS_ABOUT)] | ||
| Completions { | ||
| /// Shell to generate completions for | ||
| shell: clap_complete::Shell, |
There was a problem hiding this comment.
Completions {
/// Shell to generate completions for (auto-detected if omitted)
shell: Option<clap_complete::Shell>,
},
改成从 $SHELL 内直接获取?
There was a problem hiding this comment.
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 用户本来就少,让他们手动指定没问题。
|
@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
Adds a new
utoo completions <shell>command to generate shell completion scripts.