Skip to content

feat(cmp): add dynamic completion support to run command#546

Open
PFiS1737 wants to merge 5 commits into
MaaAssistantArknights:mainfrom
PFiS1737:feat-dynamic-cmp
Open

feat(cmp): add dynamic completion support to run command#546
PFiS1737 wants to merge 5 commits into
MaaAssistantArknights:mainfrom
PFiS1737:feat-dynamic-cmp

Conversation

@PFiS1737
Copy link
Copy Markdown
Contributor

@PFiS1737 PFiS1737 commented May 11, 2026

该 PR 使用 clap 的动态补全功能优化了 maa run <task> 的补全提示,现在可以根据配置文件动态显示补全内容。

细节

  • 新增 Tasks,用来获取当前配置的任务文件,并提供打印和补全功能。

参考

Check List

  • 移除了手动维护的 fish shell 的补全文件。
  • 更新了文档。

对软件包维护者

由于使用了新的生成补全脚本的方式(见下文),可能需要更新打包脚本。

快速体验

cargo build

# 对于 fish shell,其他类似
MAA_COMPLETE=fish ./target/debug/maa | source

# 在配置中创建几个 task
# 如果系统中已有 maa 的补全脚本,请先禁用

# 不要用 ./target/debug/maa,就直接 maa,没有这条指令也行
maa run <tab>

生成补全脚本

其中 <shell> 可以是 bashzshfishpowershellelvish

env MAA_COMPLETE=<shell> maa

Summary by Sourcery

run 任务参数添加动态、基于配置的 Shell 补全支持,并简化任务列表输出。

新功能:

  • 基于已配置的任务文件,为 run 命令的任务参数启用动态 Shell 补全。
  • 引入一个 Tasks 帮助器,用于读取已配置的任务名称,并同时提供展示和补全能力。
  • 通过在设置 MAA_COMPLETE 环境变量的情况下调用 CLI,支持为多个 Shell 生成补全脚本。

改进:

  • list 命令中,用新的 Tasks 帮助器替代手动扫描任务目录的逻辑。

文档:

  • 在所有本地化安装指南中记录如何生成补全脚本,并明确说明支持的 Shell 类型。

测试:

  • 删除已废弃的 complete 子命令对应的过时测试。

杂项:

  • 移除手动维护的 Fish Shell 补全文件,改为依赖自动生成的补全。
  • 更新 clap_complete 依赖,以启用不稳定的动态补全功能。
Original summary in English

Summary by Sourcery

Add dynamic, config-driven shell completion support for the run task argument and simplify task listing output.

New Features:

  • Enable dynamic shell completion for the run command's task parameter based on configured task files.
  • Introduce a Tasks helper to read configured task names and provide both display and completion capabilities.
  • Support generating completion scripts for multiple shells by invoking the CLI under the MAA_COMPLETE environment variable.

Enhancements:

  • Replace manual task directory scanning in the list command with reuse of the new Tasks helper.

Documentation:

  • Document how to generate completion scripts in all localized installation guides and clarify supported shells.

Tests:

  • Remove the obsolete test for the deleted complete subcommand.

Chores:

  • Remove the manually maintained Fish shell completion file and rely on generated completions.
  • Update the clap_complete dependency to enable unstable dynamic completion features.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 22.18%. Comparing base (7557252) to head (75e11e0).
⚠️ Report is 6 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (7557252) and HEAD (75e11e0). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (7557252) HEAD (75e11e0)
4 1
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PFiS1737 PFiS1737 changed the title feat(cmp): add support to dynamic completion feat(cmp): add dynamic completion support to run command May 12, 2026
@PFiS1737 PFiS1737 marked this pull request as ready for review May 12, 2026 07:37
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

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>

Sourcery 对开源项目免费使用——如果你觉得我们的评审有帮助,欢迎分享 ✨
请帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据反馈改进后续评审。
Original comment in English

Hey - I've found 2 issues, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +90 to +99
## 生成补全脚本

::: tip

对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。

:::

你可以使用下面的命令为你的 shell 生成补全脚本:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +94 to +103
## 生成补全脚本

::: tip

对于使用包管理器安装的用户,这通常是自动进行的,请先检查是否已经有补全提示了。

:::

你可以使用下面的命令为你的 shell 生成补全脚本:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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`。

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.

1 participant