@@ -3,16 +3,18 @@ extern crate colored;
3
3
extern crate git2;
4
4
extern crate license;
5
5
extern crate tokei;
6
+ #[ macro_use]
7
+ extern crate clap;
6
8
7
9
use colored:: Color ;
8
10
use colored:: * ;
9
11
use git2:: Repository ;
10
12
use license:: License ;
13
+ use clap:: { App , Arg } ;
11
14
use std:: {
12
15
cmp,
13
16
collections:: HashMap ,
14
17
convert:: From ,
15
- env,
16
18
ffi:: OsStr ,
17
19
fmt,
18
20
fmt:: Write ,
@@ -282,21 +284,17 @@ fn main() -> Result<()> {
282
284
return Err ( Error :: GitNotInstalled ) ;
283
285
}
284
286
285
- let mut args = env:: args ( ) ;
286
-
287
- if args. next ( ) . is_none ( ) {
288
- return Err ( Error :: TooFewArgs ) ;
289
- } ;
290
-
291
- let dir = if let Some ( arg) = args. next ( ) {
292
- arg
293
- } else {
294
- String :: from ( "." )
295
- } ;
296
-
297
- if args. next ( ) . is_some ( ) {
298
- return Err ( Error :: TooManyArgs ) ;
299
- } ;
287
+ let matches = App :: new ( crate_name ! ( ) )
288
+ . version ( crate_version ! ( ) )
289
+ . author ( "o2sh <[email protected] >" )
290
+ . about ( crate_description ! ( ) )
291
+ . arg ( Arg :: with_name ( "directory" )
292
+ . short ( "d" )
293
+ . long ( "dir" )
294
+ . takes_value ( true )
295
+ . default_value ( "." ) )
296
+ . get_matches ( ) ;
297
+ let dir = String :: from ( matches. value_of ( "directory" ) . unwrap ( ) ) ;
300
298
301
299
let tokei_langs = project_languages ( & dir) ;
302
300
let languages_stat = get_languages_stat ( & tokei_langs) . ok_or ( Error :: SourceCodeNotFound ) ?;
@@ -495,7 +493,6 @@ fn get_configuration(dir: &str) -> Result<Configuration> {
495
493
496
494
// Return first n most active commiters as authors within this project.
497
495
fn get_authors ( dir : & str , n : usize ) -> Vec < String > {
498
- use std:: collections:: HashMap ;
499
496
let output = Command :: new ( "git" )
500
497
. arg ( "-C" )
501
498
. arg ( dir)
@@ -673,10 +670,6 @@ enum Error {
673
670
ReadDirectory ,
674
671
/// Not in a Git Repo
675
672
NotGitRepo ,
676
- /// Too few arguments
677
- TooFewArgs ,
678
- /// Too many arguments
679
- TooManyArgs ,
680
673
}
681
674
682
675
impl fmt:: Debug for Error {
@@ -687,8 +680,6 @@ impl fmt::Debug for Error {
687
680
Error :: NoGitData => "Could not retrieve git configuration data" ,
688
681
Error :: ReadDirectory => "Could not read directory" ,
689
682
Error :: NotGitRepo => "This is not a Git Repo" ,
690
- Error :: TooFewArgs => "Too few arguments. Expected program name and a single argument." ,
691
- Error :: TooManyArgs => "Too many arguments. Expected a single argument." ,
692
683
} ;
693
684
write ! ( f, "{}" , content)
694
685
}
0 commit comments