use parse_book_source::{BookSource, Engine, diagnose};
use std::path::Path;
pub async fn run(path: &Path) {
let json = match std::fs::read_to_string(path) {
Ok(j) => j,
Err(e) => return print_config_error("读取文件失败", e),
};
let source = match BookSource::from_json(&json) {
Ok(s) => s,
Err(e) => return print_config_error("JSON 解析失败", e),
};
let engine = match Engine::new(source) {
Ok(e) => e,
Err(e) => return print_config_error("构建引擎失败", e),
};
let report = diagnose(&engine).await;
print!("{report}");
if report.healthy() {
println!("\n✓ 全部通过(○ 为未配置/跳过)");
} else {
println!("\n✗ 存在异常项,请检查上面标 ✗ 的规则");
}
}
fn print_config_error(what: &str, err: impl std::fmt::Display) {
println!("书源诊断\n ✗ 配置 {what}: {err}");
}