use spec_drift::analyzers::{DocsAnalyzer, DriftAnalyzer, MissingCoverageAnalyzer, TestsAnalyzer};
use spec_drift::parsers::RustParser;
use spec_drift::reporters::{HumanReporter, Reporter};
use spec_drift::sources::FsWalker;
use spec_drift::{Config, ConfigSource, ProjectContext};
use std::path::PathBuf;
fn main() -> anyhow::Result<()> {
let root: PathBuf = std::env::args()
.nth(1)
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("."))
.canonicalize()?;
let config_path = Config::discover(&root).unwrap_or_else(|| root.join("spec-drift.toml"));
let config = Config::load(&config_path, ConfigSource::Discovered)?;
let files = FsWalker::walk(&root)?;
let mut ctx = ProjectContext::new(&root);
ctx.rust_files = files.rust;
ctx.markdown_files = files.markdown;
ctx.yaml_files = files.yaml;
ctx.makefile_files = files.makefiles;
for rs in &ctx.rust_files {
if let Ok(facts) = RustParser::parse(rs) {
ctx.code_facts.extend(facts);
}
}
let analyzers: Vec<Box<dyn DriftAnalyzer>> = vec![
Box::new(DocsAnalyzer::default()),
Box::new(MissingCoverageAnalyzer),
Box::new(TestsAnalyzer),
];
let divergences = spec_drift::run(&ctx, &analyzers);
let divergences = spec_drift::apply_config(divergences, &config, &root);
print!("{}", HumanReporter.render(&divergences));
Ok(())
}