use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RequiredTool {
pub name: String,
pub path: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToolCheck {
pub name: String,
pub path: PathBuf,
pub available: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DoctorReport {
pub checks: Vec<ToolCheck>,
}
impl DoctorReport {
#[must_use]
pub fn is_healthy(&self) -> bool {
self.checks.iter().all(|check| check.available)
}
}
#[derive(Debug, Default, Clone, Copy)]
pub struct Doctor;
impl Doctor {
#[must_use]
pub fn check_tools(tools: &[RequiredTool]) -> DoctorReport {
let checks = tools
.iter()
.map(|tool| {
let available = fs::metadata(&tool.path).is_ok_and(|metadata| {
metadata.is_file() && metadata.permissions().mode() & 0o111 != 0
});
ToolCheck {
name: tool.name.clone(),
path: tool.path.clone(),
available,
}
})
.collect();
DoctorReport { checks }
}
}