diff --git a/examples/basic_usage.rs b/examples/basic_usage.rs new file mode 100644 index 0000000..f0a42a3 --- /dev/null +++ b/examples/basic_usage.rs @@ -0,0 +1,38 @@ +use git_commit_prefix_gen::{Analyzer, CommitConvention}; + +fn main() { + let convention = CommitConvention::default(); + let analyzer = Analyzer::with_convention(convention); + + println!("Git Commit Prefix Generator - Basic Usage Example"); + println!("================================================\n"); + + println!("This example demonstrates how to use the library to analyze git changes"); + println!("and generate commit message prefixes.\n"); + + println!("Current directory: {:?}", std::env::current_dir().unwrap()); + + match std::env::current_dir() { + Ok(path) => match analyzer.analyze(&path) { + Ok(changes) => { + println!("Found {} changed files", changes.len()); + let suggestions = analyzer.generate_suggestions(&changes); + + if suggestions.is_empty() { + println!("\nNo suggestions available (no changes detected)"); + } else { + for suggestion in &suggestions { + println!("\nSuggested commit: {}", suggestion); + if let Some(scope) = &suggestion.scope { + println!(" Type: {}", suggestion.commit_type); + println!(" Scope: {}", scope); + println!(" Confidence: {:.0}%", suggestion.confidence * 100.0); + } + } + } + } + Err(e) => println!("Error analyzing changes: {}", e), + }, + Err(e) => println!("Error getting current directory: {}", e), + } +}