refactor(cli): 判据收敛到 unlucky_cli::cli,banner 按被调用的二进制名自称(M82 复审)

去重:`looks_like_cli(args) -> bool` 落在 `unlucky_cli::cli`,两个 GUI 的 main.rs 只调用它,
判据从两份变一份。cli crate 里**不**出现 GUI 的 flag 表——语义仍是「首个 token 是裸词就接管;
首个 token 是 flag 时只有解析出真命令才接管,解析失败不接管」。原来两个 main.rs 里的 5+5 条
单测合并成 cli crate 的一份(用例集按复审要求原样搬,含 --screenshot/--renderer/--diff/
--mock/--force-state/--scale-factor、--help/-h/--version/-V、10 个已知子命令、--json 前置、
未知子命令),两个 main.rs 的旧测试已删除。

banner:新增 cli::program 模块,从 argv[0] 的 basename 取程序名(剥目录、剥 .exe、空值回落
ull),把帮助/版本/错误提示里独立出现的 `ull` 换成它——`unlucky-launcher --version` 不再自称
`ull`,也不会把人指去敲 `ull --help`。`run()` 签名未改;`ull` 自己跑时输出逐字不变(替换是
恒等),打包脚本的 `ull --version` 冒烟不受影响。
This commit is contained in:
AskaEth committed 2026-11-02 08:08:12 +08:00
1 parent fecff989e7
commit c9e6236a87
9 files changed
+275 -190

No files matched your search

+17 -6
View File
@@ -2,7 +2,7 @@
use serde_json::json;
use crate::cli::help;
use crate::cli::{help, program};
use crate::os;
use crate::output::Report;
@@ -12,18 +12,20 @@ pub const LAUNCHER_NAME: &str = "UnluckyLauncher";
/// 版本 + 系统摘要(`ull --version`,D19 §5-2 要求附带 os 摘要)。
///
/// 探测走 `core::platform::os_info::current()`(进程内缓存),未达基线时附带升级指引。
/// 自称的名字取 argv[0](M82):GUI 二进制调进来时是 `unlucky-launcher`,`ull` 自己跑时仍是 `ull`。
#[must_use]
pub fn version() -> Report {
let info = os::detect();
let invoked_as = program::name();
let data = json!({
"name": "ull",
"name": invoked_as,
"package": env!("CARGO_PKG_NAME"),
"version": env!("CARGO_PKG_VERSION"),
"os": os::to_json(&info),
});
let mut human = vec![
format!(
"ull {}({})",
"{invoked_as} {}({})",
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_NAME")
),
@@ -38,20 +40,29 @@ pub fn version() -> Report {
pub fn welcome() -> Report {
let version_report = version();
let mut human = version_report.human;
let text = general_help();
human.push(String::new());
human.extend(help::general().lines().map(str::to_string));
human.extend(text.lines().map(str::to_string));
let mut data = version_report.data;
data["help"] = json!(help::general());
data["help"] = json!(text);
Report::new(data, human)
}
/// 帮助(`ull help <命令>` 给该命令,未知主题退回总帮助)。
#[must_use]
pub fn help(topic: Option<&str>) -> Report {
let text = topic.and_then(help::topic).unwrap_or_else(help::general);
let text = match topic.and_then(help::topic) {
Some(text) => program::rename(text, &program::name()),
None => general_help(),
};
let data = json!({
"topic": topic,
"text": text,
});
Report::new(data, text.lines().map(str::to_string).collect())
}
/// 总帮助,按被调用的二进制名自述(`ull` 自己跑时逐字不变)。
fn general_help() -> String {
program::rename(help::general(), &program::name())
}