@@ -7,47 +7,45 @@ use std::{env, fs, process};
77#[ derive( Parser , Debug ) ]
88#[ command( author, version, about, long_about = None ) ]
99struct Args {
10- /// Path to the Git repository ( default = current directory)
11- #[ arg( short, long, default_value = "" ) ]
12- repo_path : String ,
10+ /// Path to the Git repository [ default = current directory]
11+ #[ arg( short, long) ]
12+ repo_path : Option < String > ,
1313
14- /// Commit hash which commits should be analyzed ( default = all)
15- #[ arg( short, long, default_value = "" ) ]
16- after : String ,
14+ /// Commit hash which commits should be analyzed [ default = all]
15+ #[ arg( short, long) ]
16+ after : Option < String > ,
1717
18- /// Commit hash before which commits should be analyzed ( default = all)
19- #[ arg( short, long, default_value = "" ) ]
20- before : String ,
18+ /// Commit hash before which commits should be analyzed [ default = all]
19+ #[ arg( short, long) ]
20+ before : Option < String > ,
2121
22- /// User name for commit analysis ( default = git config user.name)
23- #[ arg( short, long, default_value = "" ) ]
24- user : String ,
22+ /// User name for commit analysis [ default = ` git config user.name`]
23+ #[ arg( short, long) ]
24+ user : Option < String > ,
2525
26- /// Amount of of top committers to show ( default = 3)
27- #[ arg( short, long, default_value_t = 3 ) ]
28- top_committers : usize ,
26+ /// Amount of of top committers to show [ default = 3]
27+ #[ arg( short, long) ]
28+ top_committers : Option < usize > ,
2929}
3030
3131fn main ( ) {
3232 let args = Args :: parse ( ) ;
3333
34- let current_dir = if !args. repo_path . is_empty ( ) {
35- args. repo_path . clone ( )
36- } else {
37- env:: current_dir ( )
34+ let current_dir = match args. repo_path {
35+ Some ( repo_path) => repo_path. clone ( ) ,
36+ None => env:: current_dir ( )
3837 . expect ( "Failed to get current directory" )
3938 . to_string_lossy ( )
40- . to_string ( )
39+ . to_string ( ) ,
4140 } ;
4241
4342 if !check_directory_and_git ( & current_dir) {
4443 process:: exit ( 1 ) ;
4544 }
4645
47- let user_name = if args. user . is_empty ( ) {
48- analyzer:: get_user_name ( )
49- } else {
50- args. user . clone ( )
46+ let user_name = match args. user {
47+ Some ( user) => user. clone ( ) ,
48+ None => analyzer:: get_user_name ( ) ,
5149 } ;
5250
5351 if user_name. is_empty ( ) {
@@ -62,7 +60,11 @@ fn main() {
6260 process:: exit ( 1 ) ;
6361 }
6462
65- let commits = analyzer:: get_commits ( & repo, & args. after , & args. before ) ;
63+ let commits = analyzer:: get_commits (
64+ & repo,
65+ & args. after . unwrap_or_default ( ) ,
66+ & args. before . unwrap_or_default ( ) ,
67+ ) ;
6668
6769 if commits. is_err ( ) {
6870 eprintln ! ( "Error: Failed to get commits." ) ;
@@ -81,7 +83,7 @@ fn main() {
8183 println ! ( ) ;
8284 analyzer:: show_coding_habits ( & commits_vec) ;
8385 println ! ( ) ;
84- analyzer:: show_top_committers ( args. top_committers , & commits_vec) ;
86+ analyzer:: show_top_committers ( args. top_committers . unwrap_or ( 3 ) , & commits_vec) ;
8587}
8688
8789/// Check if the specified path is a directory and a Git repository.
0 commit comments