john-slop/examples/analyze_path.rs

32 lines
1021 B
Rust

//! Stream and analyze every supported document under a path.
use std::{env, error::Error, path::PathBuf};
use john_slop::{AnalysisContext, Config, Detector, read_inputs};
fn main() -> Result<(), Box<dyn Error>> {
let path = env::args_os()
.nth(1)
.map_or_else(|| PathBuf::from("examples/fixtures"), PathBuf::from);
let config = Config::embedded();
let detector = Detector::new(&config)?;
for document in read_inputs(&config, &path)? {
match document {
Ok(document) => {
let context = AnalysisContext::for_source(&document.source);
let analysis = detector.analyze_with(&document.content, &context);
println!(
"{}: confidence={}, findings={}",
document.source,
analysis.confidence.score(),
analysis.findings.len()
);
}
Err(error) => eprintln!("input error: {error}"),
}
}
Ok(())
}