@@ -14,6 +14,8 @@ use crate::{AsciiArt, CommitInfo, Configuration, Error, InfoFieldOn};
14
14
15
15
type Result < T > = std:: result:: Result < T , crate :: Error > ;
16
16
17
+ const LICENSE_FILES : [ & str ; 3 ] = [ "LICENSE" , "LICENCE" , "COPYING" ] ;
18
+
17
19
pub struct Info {
18
20
git_version : String ,
19
21
git_username : String ,
@@ -37,7 +39,7 @@ pub struct Info {
37
39
bold_enabled : bool ,
38
40
no_color_blocks : bool ,
39
41
custom_image : Option < DynamicImage > ,
40
- image_backend : Option < Box < dyn ImageBackend > >
42
+ image_backend : Option < Box < dyn ImageBackend > > ,
41
43
}
42
44
43
45
impl std:: fmt:: Display for Info {
@@ -649,22 +651,26 @@ impl Info {
649
651
}
650
652
651
653
fn get_project_license ( dir : & str ) -> Result < String > {
654
+ fn is_license_file < S : AsRef < str > > ( file_name : S ) -> bool {
655
+ LICENSE_FILES
656
+ . iter ( )
657
+ . any ( |& name| file_name. as_ref ( ) . starts_with ( name) )
658
+ }
659
+
652
660
let detector = Detector :: new ( ) ?;
653
661
654
662
let mut output = fs:: read_dir ( dir)
655
663
. map_err ( |_| Error :: ReadDirectory ) ?
656
664
. filter_map ( std:: result:: Result :: ok)
657
665
. map ( |entry| entry. path ( ) )
658
- . filter (
659
- |entry| {
660
- entry. is_file ( )
661
- && entry
662
- . file_name ( )
663
- . map ( OsStr :: to_string_lossy)
664
- . iter ( )
665
- . any ( |x| x. starts_with ( "LICENSE" ) || x. starts_with ( "COPYING" ) )
666
- } , // TODO: multiple prefixes, like COPYING?
667
- )
666
+ . filter ( |entry| {
667
+ entry. is_file ( )
668
+ && entry
669
+ . file_name ( )
670
+ . map ( OsStr :: to_string_lossy)
671
+ . map ( is_license_file)
672
+ . unwrap_or_default ( )
673
+ } )
668
674
. filter_map ( |entry| {
669
675
let contents = fs:: read_to_string ( entry) . unwrap_or_default ( ) ;
670
676
detector. analyze ( & contents)
0 commit comments