use vex_app::VexHome;
use vex_app::doctor::{CheckStatus, run_doctor};
pub fn run() {
let vex_home = match VexHome::new(None) {
Ok(h) => h,
Err(e) => {
eprintln!("Error: {e}");
std::process::exit(1);
}
};
let checks = run_doctor(&vex_home);
println!("vex doctor");
println!("{}", "─".repeat(50));
for check in &checks {
let symbol = check.symbol();
let color_code = match check.status {
CheckStatus::Pass => "\x1b[32m", CheckStatus::Fail => "\x1b[31m", CheckStatus::Warning => "\x1b[33m", };
let reset = "\x1b[0m";
println!(
" {color_code}{symbol}{reset} {:<16} {}",
check.name, check.message
);
if let Some(hint) = &check.fix_hint
&& check.status != CheckStatus::Pass
{
println!(" {color_code}↳ {hint}{reset}");
}
}
let failures = checks
.iter()
.filter(|c| c.status == CheckStatus::Fail)
.count();
let warnings = checks
.iter()
.filter(|c| c.status == CheckStatus::Warning)
.count();
println!();
if failures > 0 {
println!(
"\x1b[31m{failures} error(s)\x1b[0m{}",
if warnings > 0 {
format!(", \x1b[33m{warnings} warning(s)\x1b[0m")
} else {
String::new()
}
);
std::process::exit(1);
} else if warnings > 0 {
println!("\x1b[33m{warnings} warning(s)\x1b[0m");
} else {
println!("\x1b[32mAll checks passed!\x1b[0m");
}
}