use scribe_analyzer::{analyze_repository, Config};
use scribe_core::*;
use scribe_patterns::*;
use std::path::Path;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
env_logger::init();
println!("π Scribe Repository Analysis Example");
println!("====================================\n");
let repo_path = std::env::args().nth(1).unwrap_or_else(|| ".".to_string());
println!("π Analyzing repository: {}", repo_path);
let config = Config::default()
.with_git_integration(true)
.with_parallel_processing(true);
println!("βοΈ Configuration: {:?}\n", config.general);
println!("π Starting analysis...");
let start_time = std::time::Instant::now();
let analysis = analyze_repository(&repo_path, &config).await?;
let duration = start_time.elapsed();
println!("β
Analysis completed in {:.2}s\n", duration.as_secs_f64());
println!("{}\n", analysis.summary());
println!("π Top 10 Most Important Files:");
println!("================================");
for (rank, (file_path, score)) in analysis.top_files(10).iter().enumerate() {
println!("{:2}. {:<50} {:.3}", rank + 1, file_path, score);
}
let threshold = 0.7;
let high_importance_files = analysis.files_above_threshold(threshold);
if !high_importance_files.is_empty() {
println!("\nπ― High Importance Files (score > {}):", threshold);
println!("========================================");
for (file_path, score) in high_importance_files {
println!(" {:<50} {:.3}", file_path, score);
}
}
println!("\nπ Analysis Details:");
println!("===================");
println!("Version: {}", scribe_analyzer::VERSION);
println!("Files analyzed: {}", analysis.file_count());
println!("Scribe version: {}", analysis.metadata.scribe_version);
println!(
"Features used: {}",
analysis.metadata.features_enabled.join(", ")
);
#[cfg(feature = "graph")]
{
if let Some(ref centrality_scores) = analysis.centrality_scores {
println!("\nπΈοΈ Graph Analysis Results:");
println!("=========================");
let mut centrality_sorted: Vec<_> = centrality_scores.iter().collect();
centrality_sorted
.sort_by(|a, b| b.1.partial_cmp(a.1).unwrap_or(std::cmp::Ordering::Equal));
println!("Top 5 files by centrality:");
for (rank, (file, score)) in centrality_sorted.iter().take(5).enumerate() {
println!("{:2}. {:<50} {:.4}", rank + 1, file, score);
}
}
}
#[cfg(feature = "patterns")]
{
println!("\nπ― Pattern Matching Demo:");
println!("========================");
let mut source_matcher = scribe_patterns::presets::source_code()?;
let mut doc_matcher = scribe_patterns::presets::documentation()?;
let source_files = analysis
.files
.iter()
.filter(|f| source_matcher.should_process(&f.path).unwrap_or(false))
.count();
let doc_files = analysis
.files
.iter()
.filter(|f| doc_matcher.should_process(&f.path).unwrap_or(false))
.count();
println!("Source code files: {}", source_files);
println!("Documentation files: {}", doc_files);
}
println!("\nπ Analysis complete!");
Ok(())
}
trait ConfigExt {
fn with_git_integration(self, enabled: bool) -> Self;
fn with_parallel_processing(self, enabled: bool) -> Self;
}
impl ConfigExt for Config {
fn with_git_integration(mut self, enabled: bool) -> Self {
self.git.enabled = enabled;
self
}
fn with_parallel_processing(mut self, enabled: bool) -> Self {
self
}
}