use anyhow::{anyhow, Result};
use camino::Utf8PathBuf;
use cordance_core::evidence::EvidenceMap;
pub fn run(rule: &str, target: &Utf8PathBuf) -> Result<()> {
let map_path = target.join(".cordance/evidence-map.json");
if !map_path.exists() {
return Err(anyhow!(
"No evidence map at {map_path}. Run 'cordance pack' first."
));
}
let raw = std::fs::read_to_string(&map_path)?;
let map: EvidenceMap = serde_json::from_str(&raw)?;
let matches: Vec<_> = map
.rules
.iter()
.filter(|e| e.rule_id.contains(rule) || e.text.contains(rule))
.collect();
if matches.is_empty() {
println!("No rule found matching '{rule}'");
return Ok(());
}
for entry in matches {
println!("Rule: {}", entry.rule_id);
println!("Text: {}", entry.text);
println!("Sources:");
for source in &entry.sources {
println!(" - {} ({})", source.path, source.kind);
}
println!();
}
Ok(())
}