use std::path::{Path, PathBuf};
#[must_use]
pub fn find_project_root(start: &Path) -> PathBuf {
for ancestor in start.ancestors() {
if HealPaths::new(ancestor).config().is_file() {
return ancestor.to_path_buf();
}
}
start.to_path_buf()
}
#[derive(Debug, Clone)]
pub struct HealPaths {
root: PathBuf,
}
impl HealPaths {
pub fn new(project_root: impl AsRef<Path>) -> Self {
Self {
root: project_root.as_ref().join(".heal"),
}
}
#[must_use]
pub fn root(&self) -> &Path {
&self.root
}
#[must_use]
pub fn config(&self) -> PathBuf {
self.root.join("config.toml")
}
#[must_use]
pub fn calibration(&self) -> PathBuf {
self.root.join("calibration.toml")
}
#[must_use]
pub fn findings_dir(&self) -> PathBuf {
self.root.join("findings")
}
#[must_use]
pub fn findings_latest(&self) -> PathBuf {
self.findings_dir().join("latest.json")
}
#[must_use]
pub fn findings_fixed(&self) -> PathBuf {
self.findings_dir().join("fixed.json")
}
#[must_use]
pub fn findings_regressed_log(&self) -> PathBuf {
self.findings_dir().join("regressed.jsonl")
}
#[must_use]
pub fn findings_accepted(&self) -> PathBuf {
self.findings_dir().join("accepted.json")
}
pub fn ensure(&self) -> std::io::Result<()> {
for dir in [self.root.as_path(), &self.findings_dir()] {
std::fs::create_dir_all(dir)?;
}
Ok(())
}
}