|
| 1 | +use bytes_radar::{FileCategory, FileMetrics, ProjectAnalysis, Result}; |
| 2 | + |
| 3 | +fn main() -> Result<()> { |
| 4 | + let mut project = ProjectAnalysis::new("my-rust-project"); |
| 5 | + |
| 6 | + let main_rs = FileMetrics::new("src/main.rs", "Rust".to_string(), 50, 35, 10, 5)? |
| 7 | + .with_category(FileCategory::Source) |
| 8 | + .with_size_bytes(1200); |
| 9 | + |
| 10 | + let lib_rs = FileMetrics::new("src/lib.rs", "Rust".to_string(), 80, 60, 15, 5)? |
| 11 | + .with_category(FileCategory::Source) |
| 12 | + .with_size_bytes(2000); |
| 13 | + |
| 14 | + let test_rs = FileMetrics::new( |
| 15 | + "tests/integration_test.rs", |
| 16 | + "Rust".to_string(), |
| 17 | + 45, |
| 18 | + 35, |
| 19 | + 5, |
| 20 | + 5, |
| 21 | + )? |
| 22 | + .with_category(FileCategory::Test) |
| 23 | + .with_size_bytes(950); |
| 24 | + |
| 25 | + let readme_md = FileMetrics::new("README.md", "Markdown".to_string(), 25, 20, 0, 5)? |
| 26 | + .with_category(FileCategory::Documentation) |
| 27 | + .with_size_bytes(600); |
| 28 | + |
| 29 | + let cargo_toml = FileMetrics::new("Cargo.toml", "TOML".to_string(), 15, 12, 2, 1)? |
| 30 | + .with_category(FileCategory::Configuration) |
| 31 | + .with_size_bytes(400); |
| 32 | + |
| 33 | + project.add_file_metrics(main_rs)?; |
| 34 | + project.add_file_metrics(lib_rs)?; |
| 35 | + project.add_file_metrics(test_rs)?; |
| 36 | + project.add_file_metrics(readme_md)?; |
| 37 | + project.add_file_metrics(cargo_toml)?; |
| 38 | + |
| 39 | + let summary = project.get_summary(); |
| 40 | + |
| 41 | + println!("=== Custom Project Analysis ===\n"); |
| 42 | + println!("Project: {}", summary.project_name); |
| 43 | + println!("Total Files: {}", summary.total_files); |
| 44 | + println!("Total Lines: {}", summary.total_lines); |
| 45 | + println!("Code Lines: {}", summary.total_code_lines); |
| 46 | + println!("Comment Lines: {}", summary.total_comment_lines); |
| 47 | + println!("Blank Lines: {}", summary.total_blank_lines); |
| 48 | + println!("Total Size: {} bytes", summary.total_size_bytes); |
| 49 | + |
| 50 | + println!("\n=== Language Breakdown ==="); |
| 51 | + for stats in project.get_language_statistics() { |
| 52 | + println!("{}:", stats.language_name); |
| 53 | + println!(" Files: {}", stats.file_count); |
| 54 | + println!(" Lines: {}", stats.total_lines); |
| 55 | + println!(" Code: {}", stats.code_lines); |
| 56 | + println!(" Comments: {}", stats.comment_lines); |
| 57 | + println!(" Complexity: {:.1}%", stats.complexity_ratio * 100.0); |
| 58 | + println!(" Documentation: {:.1}%", stats.documentation_ratio * 100.0); |
| 59 | + println!(); |
| 60 | + } |
| 61 | + |
| 62 | + println!("=== File Details ==="); |
| 63 | + for (lang_name, lang_analysis) in &project.language_analyses { |
| 64 | + println!("{}:", lang_name); |
| 65 | + for file in &lang_analysis.file_metrics { |
| 66 | + println!( |
| 67 | + " {} ({:?}): {} lines, {} bytes", |
| 68 | + file.file_path, file.category, file.total_lines, file.size_bytes |
| 69 | + ); |
| 70 | + } |
| 71 | + println!(); |
| 72 | + } |
| 73 | + |
| 74 | + Ok(()) |
| 75 | +} |
0 commit comments