Skip to content

feat: 支持命令行参数-i指定启动实例名称#137

Merged
MistEO merged 6 commits intoMistEO:mainfrom
ShadowLemoon:feat/console-start-tab
Apr 3, 2026
Merged

feat: 支持命令行参数-i指定启动实例名称#137
MistEO merged 6 commits intoMistEO:mainfrom
ShadowLemoon:feat/console-start-tab

Conversation

@ShadowLemoon
Copy link
Copy Markdown
Contributor

@ShadowLemoon ShadowLemoon commented Mar 30, 2026

Summary by Sourcery

通过新增命令行参数来支持选择要自动启动的实例,并将其集成到应用的自动启动流程中。

新功能:

  • 添加一个 Tauri 命令,用于读取自动启动模式下用于指定启动实例名称的 -i/--instance CLI 参数。
  • 允许前端的自动启动逻辑在启动时优先采用 CLI 指定的实例,而不是已配置的默认自动启动实例。
Original summary in English

Summary by Sourcery

Support selecting which instance to auto-start via a new command-line argument and integrate it into the app's autostart flow.

New Features:

  • Add a Tauri command to read the -i/--instance CLI argument specifying the desired startup instance name in autostart mode.
  • Allow the frontend autostart logic to prioritize the CLI-specified instance over the configured default auto-start instance when launching.

Copy link
Copy Markdown
Contributor

@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 - 我发现了 1 个问题

给 AI Agent 的提示
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/commands/system.rs" line_range="541-550" />
<code_context>

+/// 获取命令行 -i/--instance 参数指定的启动实例名称
+#[tauri::command]
+pub fn get_start_instance() -> Option<String> {
+    let args: Vec<String> = std::env::args().collect();
+    let mut iter = args.iter();
+    while let Some(arg) = iter.next() {
+        if arg == "-i" || arg == "--instance" {
+            return iter.next().cloned();
+        }
+        if let Some(value) = arg.strip_prefix("-i=") {
+            return Some(value.to_string());
+        }
+        if let Some(value) = arg.strip_prefix("--instance=") {
+            return Some(value.to_string());
+        }
+    }
+    None
+}
+
</code_context>
<issue_to_address>
**question:** 请阐明在存在多个 `-i/--instance` 标志,或标志缺少值时的行为。

当前函数会返回它遇到的第一个 `-i/--instance`,并且不做校验地将下一个 token 当作其值,即便这个 token 本身是以 `-` 开头的。这样一来,当存在多个 `-i` 标志或值缺失(例如:`-i -v`)时,可能会在没有任何提示的情况下产生出乎意料的结果。建议要么校验该值不像是另一个标志(例如:拒绝或忽略以 `-` 开头的值),要么对多次出现的情况定义一个明确规则(例如:第一次出现优先或最后一次出现优先),并在实现中严格遵守并在文档中说明。
</issue_to_address>

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/commands/system.rs" line_range="541-550" />
<code_context>

+/// 获取命令行 -i/--instance 参数指定的启动实例名称
+#[tauri::command]
+pub fn get_start_instance() -> Option<String> {
+    let args: Vec<String> = std::env::args().collect();
+    let mut iter = args.iter();
+    while let Some(arg) = iter.next() {
+        if arg == "-i" || arg == "--instance" {
+            return iter.next().cloned();
+        }
+        if let Some(value) = arg.strip_prefix("-i=") {
+            return Some(value.to_string());
+        }
+        if let Some(value) = arg.strip_prefix("--instance=") {
+            return Some(value.to_string());
+        }
+    }
+    None
+}
+
</code_context>
<issue_to_address>
**question:** Clarify behavior when multiple `-i/--instance` flags are present or when the flag is missing a value.

Right now, the function returns the first `-i/--instance` it sees and blindly uses the next token as the value, even if it starts with `-`. That means multiple `-i` flags or a missing value (e.g., `-i -v`) can silently produce surprising results. Consider either validating that the value doesn’t look like another flag (e.g., reject or ignore values starting with `-`), or defining a clear rule for multiple occurrences (e.g., first wins vs last wins) and enforcing/documenting it.
</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.

@ShadowLemoon ShadowLemoon marked this pull request as draft March 30, 2026 23:28
@ShadowLemoon ShadowLemoon marked this pull request as ready for review March 31, 2026 18:30
Comment on lines +563 to +573
/// 获取命令行 -c/--controller 参数指定的控制器名称
#[tauri::command]
pub fn get_controller_override() -> Option<String> {
get_cli_arg_value("-c", "--controller")
}

/// 检查命令行是否包含 -k/--kill 参数(任务完成后关闭自身)
#[tauri::command]
pub fn has_close_flag() -> bool {
std::env::args().any(|arg| arg == "-k" || arg == "--kill")
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

不赞成添加这两个参数,应该根据 tab 里的原有配置来

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

kill参数我觉得是必要的,因为如果是人工操作可以手动关闭游戏,或者之后加些手动操作(比如送快递)。运行同一个配置组的时候不希望跑完就自动关。

@MistEO
Copy link
Copy Markdown
Owner

MistEO commented Apr 3, 2026

kill 名字有点怪,感觉换个名字好一点

- 将 -k/--kill 重命名为 -q/--quit-after-run,语义更明确

- 为 get_cli_arg_value 补回 -x=value 和 --name=value 格式支持(重构时遗漏)

- 统一 Rust 端函数名、注释和前端日志文本

Made-with: Cursor
@MistEO MistEO merged commit 0f0d301 into MistEO:main Apr 3, 2026
15 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