use crate::{error::Result, load::load_file, model::normalize};
use camino::Utf8Path;
pub fn run(config_path: &Utf8Path) -> Result<()> {
let raw = load_file(config_path)?;
let (policy, default_warnings) = normalize(raw)?;
let mut errors = Vec::new();
let mut warnings = default_warnings;
for editable_path in &policy.paths.editable {
if policy.paths.protected.contains(editable_path) {
errors.push(format!(
"Path conflict: '{editable_path}' is listed in both paths.editable and paths.protected."
));
}
}
for role in policy.roles.values() {
if role.editable.is_empty() {
warnings.push(format!(
"Role '{}': has no editable paths. It will not be able to modify anything.",
role.name
));
}
for editable_path in &role.editable {
if role.forbidden.contains(editable_path) {
errors.push(format!(
"Role '{}': Path conflict - '{editable_path}' is listed in both editable and forbidden.",
role.name
));
}
}
}
let has_errors = !errors.is_empty();
for warn in warnings {
println!("⚠️ Warning: {warn}");
}
for err in errors {
eprintln!("❌ Error: {err}");
}
if has_errors {
eprintln!("\nLint failed with errors.");
std::process::exit(1);
} else {
println!("\n✅ Lint passed.");
Ok(())
}
}