feat(cmp): add dynamic completion support to run command#546
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #546 +/- ##
===========================================
- Coverage 71.86% 22.18% -49.69%
===========================================
Files 69 6 -63
Lines 6412 284 -6128
Branches 6412 284 -6128
===========================================
- Hits 4608 63 -4545
+ Misses 1477 220 -1257
+ Partials 327 1 -326 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
run command
There was a problem hiding this comment.
Hey - 我发现了 2 个问题,并给出了一些总体反馈:
- 考虑对
Tasks.names进行排序(例如在Tasks::new中构造Self之前),这样maa list和补全建议在不同文件系统遍历顺序下都能保持确定性。 - 之前的
Command::List在任务目录缺失时会打印"No tasks found",而新的Tasks实现则什么都不打印;如果你认为这条消息有用,可以在列表为空时保留一个类似的用户提示。
供 AI 代理使用的提示
Please address the comments from this code review:
## Overall Comments
- 考虑对 `Tasks.names` 进行排序(例如在 `Tasks::new` 中构造 `Self` 之前),这样 `maa list` 和补全建议在不同文件系统遍历顺序下都能保持确定性。
- 之前的 `Command::List` 在任务目录缺失时会打印 `"No tasks found"`,而新的 `Tasks` 实现则什么都不打印;如果你认为这条消息有用,可以在列表为空时保留一个类似的用户提示。
## Individual Comments
### Comment 1
<location path="crates/maa-cli/docs/ko-KR/install.md" line_range="90-99" />
<code_context>
- `git2`: 提供 `libgit2` 资源更新后端,这个特性默认启用;
- `vendored-openssl`: 自行编译 `openssl` 库,而不是使用系统的 `openssl` 库,这个特性默认禁用,这个特性通常在你的系统没有安装 `openssl` 库或者 `openssl` 版本过低时启用。
+## 生成补全脚本
+
+::: tip
+
+对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。
+
+:::
+
+你可以使用下面的命令为你的 shell 生成补全脚本:
+
+```bash
+env MAA_COMPLETE=<shell> maa
+```
+
+其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
+
## 安装 MaaCore 及资源
</code_context>
<issue_to_address>
**issue (typo):** 新增的补全部分在 ko-KR 文档中是中文而不是韩文。
在这个 `ko-KR` 文件中,新补全部分(标题和内容)是用简体中文编写的。请将这一部分翻译成韩文,以保持该文件与其余文档在语言环境上的一致性。
</issue_to_address>
### Comment 2
<location path="crates/maa-cli/docs/zh-TW/install.md" line_range="94-103" />
<code_context>
- `git2`: 提供 `libgit2` 资源更新后端,这个特性默认启用;
- `vendored-openssl`: 自行编译 `openssl` 库,而不是使用系统的 `openssl` 库,这个特性默认禁用,这个特性通常在你的系统没有安装 `openssl` 库或者 `openssl` 版本过低时启用。
+## 生成补全脚本
+
+::: tip
+
+对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。
+
+:::
+
+你可以使用下面的命令为你的 shell 生成补全脚本:
+
+```bash
+env MAA_COMPLETE=<shell> maa
+```
+
+其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
+
## 安装 MaaCore 及资源
</code_context>
<issue_to_address>
**suggestion (typo):** zh-TW 文档中新补全部分使用的是简体中文,而不是繁体中文。
这一部分使用的是简体中文(例如“生成补全脚本”、“补全”、“脚本”)。对于 `zh-TW`,请将这些内容转换为繁体中文(例如“生成補全腳本”以及其他对应的繁体形式),以匹配该语言环境。
Suggested implementation:
```
## 生成補全腳本
::: tip
對於使用套件管理器安裝的使用者,這通常會自動完成,請先檢查是否已經有補全提示了。
:::
你可以使用下面的指令為你的 shell 生成補全腳本:
```
```
其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
```
</issue_to_address>请帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据反馈改进后续评审。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- Consider sorting
Tasks.names(e.g., before constructingSelfinTasks::new) somaa listand completion suggestions are deterministic regardless of filesystem iteration order. - The previous
Command::Listprinted"No tasks found"when the task directory was missing, while the newTasksimplementation just prints nothing; if the message was useful, you might want to preserve a similar user-facing hint when the list is empty.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider sorting `Tasks.names` (e.g., before constructing `Self` in `Tasks::new`) so `maa list` and completion suggestions are deterministic regardless of filesystem iteration order.
- The previous `Command::List` printed `"No tasks found"` when the task directory was missing, while the new `Tasks` implementation just prints nothing; if the message was useful, you might want to preserve a similar user-facing hint when the list is empty.
## Individual Comments
### Comment 1
<location path="crates/maa-cli/docs/ko-KR/install.md" line_range="90-99" />
<code_context>
- `git2`: 提供 `libgit2` 资源更新后端,这个特性默认启用;
- `vendored-openssl`: 自行编译 `openssl` 库,而不是使用系统的 `openssl` 库,这个特性默认禁用,这个特性通常在你的系统没有安装 `openssl` 库或者 `openssl` 版本过低时启用。
+## 生成补全脚本
+
+::: tip
+
+对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。
+
+:::
+
+你可以使用下面的命令为你的 shell 生成补全脚本:
+
+```bash
+env MAA_COMPLETE=<shell> maa
+```
+
+其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
+
## 安装 MaaCore 及资源
</code_context>
<issue_to_address>
**issue (typo):** New completion section is in Chinese rather than Korean in the ko-KR documentation.
In this `ko-KR` file, the new completion section (title and content) is written in Simplified Chinese. Please translate this section into Korean to keep the locale consistent with the rest of the document.
</issue_to_address>
### Comment 2
<location path="crates/maa-cli/docs/zh-TW/install.md" line_range="94-103" />
<code_context>
- `git2`: 提供 `libgit2` 资源更新后端,这个特性默认启用;
- `vendored-openssl`: 自行编译 `openssl` 库,而不是使用系统的 `openssl` 库,这个特性默认禁用,这个特性通常在你的系统没有安装 `openssl` 库或者 `openssl` 版本过低时启用。
+## 生成补全脚本
+
+::: tip
+
+对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。
+
+:::
+
+你可以使用下面的命令为你的 shell 生成补全脚本:
+
+```bash
+env MAA_COMPLETE=<shell> maa
+```
+
+其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
+
## 安装 MaaCore 及资源
</code_context>
<issue_to_address>
**suggestion (typo):** New completion section in zh-TW uses Simplified Chinese instead of Traditional Chinese.
This section is written in Simplified Chinese (e.g., “生成补全脚本”, “补全”, “脚本”). For `zh-TW`, please convert these to Traditional characters (e.g., “生成補全腳本” and corresponding Traditional forms throughout) to match the locale.
Suggested implementation:
```
## 生成補全腳本
::: tip
對於使用套件管理器安裝的使用者,這通常會自動完成,請先檢查是否已經有補全提示了。
:::
你可以使用下面的指令為你的 shell 生成補全腳本:
```
```
其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| ## 生成补全脚本 | ||
|
|
||
| ::: tip | ||
|
|
||
| 对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。 | ||
|
|
||
| ::: | ||
|
|
||
| 你可以使用下面的命令为你的 shell 生成补全脚本: | ||
|
|
There was a problem hiding this comment.
issue (typo): 新增的补全部分在 ko-KR 文档中是中文而不是韩文。
在这个 ko-KR 文件中,新补全部分(标题和内容)是用简体中文编写的。请将这一部分翻译成韩文,以保持该文件与其余文档在语言环境上的一致性。
Original comment in English
issue (typo): New completion section is in Chinese rather than Korean in the ko-KR documentation.
In this ko-KR file, the new completion section (title and content) is written in Simplified Chinese. Please translate this section into Korean to keep the locale consistent with the rest of the document.
| ## 生成补全脚本 | ||
|
|
||
| ::: tip | ||
|
|
||
| 对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。 | ||
|
|
||
| ::: | ||
|
|
||
| 你可以使用下面的命令为你的 shell 生成补全脚本: | ||
|
|
There was a problem hiding this comment.
suggestion (typo): zh-TW 文档中新补全部分使用的是简体中文,而不是繁体中文。
这一部分使用的是简体中文(例如“生成补全脚本”、“补全”、“脚本”)。对于 zh-TW,请将这些内容转换为繁体中文(例如“生成補全腳本”以及其他对应的繁体形式),以匹配该语言环境。
Suggested implementation:
## 生成補全腳本
::: tip
對於使用套件管理器安裝的使用者,這通常會自動完成,請先檢查是否已經有補全提示了。
:::
你可以使用下面的指令為你的 shell 生成補全腳本:
其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
Original comment in English
suggestion (typo): New completion section in zh-TW uses Simplified Chinese instead of Traditional Chinese.
This section is written in Simplified Chinese (e.g., “生成补全脚本”, “补全”, “脚本”). For zh-TW, please convert these to Traditional characters (e.g., “生成補全腳本” and corresponding Traditional forms throughout) to match the locale.
Suggested implementation:
## 生成補全腳本
::: tip
對於使用套件管理器安裝的使用者,這通常會自動完成,請先檢查是否已經有補全提示了。
:::
你可以使用下面的指令為你的 shell 生成補全腳本:
其中 `<shell>` 可以是 `bash`、`zsh`、`fish`、`powershell` 或 `elvish`。
该 PR 使用
clap的动态补全功能优化了maa run <task>的补全提示,现在可以根据配置文件动态显示补全内容。细节
Tasks,用来获取当前配置的任务文件,并提供打印和补全功能。参考
Check List
对软件包维护者
由于使用了新的生成补全脚本的方式(见下文),可能需要更新打包脚本。
快速体验
生成补全脚本
其中
<shell>可以是bash、zsh、fish、powershell或elvish。Summary by Sourcery
为
run任务参数添加动态、基于配置的 Shell 补全支持,并简化任务列表输出。新功能:
run命令的任务参数启用动态 Shell 补全。Tasks帮助器,用于读取已配置的任务名称,并同时提供展示和补全能力。MAA_COMPLETE环境变量的情况下调用 CLI,支持为多个 Shell 生成补全脚本。改进:
list命令中,用新的Tasks帮助器替代手动扫描任务目录的逻辑。文档:
测试:
complete子命令对应的过时测试。杂项:
clap_complete依赖,以启用不稳定的动态补全功能。Original summary in English
Summary by Sourcery
Add dynamic, config-driven shell completion support for the
runtask argument and simplify task listing output.New Features:
runcommand's task parameter based on configured task files.Taskshelper to read configured task names and provide both display and completion capabilities.MAA_COMPLETEenvironment variable.Enhancements:
listcommand with reuse of the newTaskshelper.Documentation:
Tests:
completesubcommand.Chores:
clap_completedependency to enable unstable dynamic completion features.