Add example files
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-01-31 11:41:58 +00:00
parent 86d1fd74dc
commit c22a3bd79b

38
examples/basic_usage.rs Normal file
View File

@@ -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),
}
}