@@ -42,19 +42,26 @@ impl From<&std::path::Path> for DataFormat {
4242 . file_name ( )
4343 . and_then ( |e| e. to_str ( ) )
4444 . unwrap_or_default ( ) ;
45- let ( file_stem, mut ext) = file_name. split_once ( '.' ) . unwrap_or ( ( file_name, "" ) ) ;
46- if file_stem. is_empty ( ) {
47- ( _, ext) = file_stem. split_once ( '.' ) . unwrap_or ( ( file_name, "" ) ) ;
48- }
49- match ext {
50- #[ cfg( feature = "json" ) ]
51- "json" => DataFormat :: Json ,
52- #[ cfg( feature = "json" ) ]
53- "jsonl" => DataFormat :: JsonLines ,
54- #[ cfg( feature = "term-svg" ) ]
55- "term.svg" => Self :: TermSvg ,
56- _ => DataFormat :: Text ,
45+ let mut ext = file_name. strip_prefix ( '.' ) . unwrap_or ( file_name) ;
46+ while let Some ( ( _, new_ext) ) = ext. split_once ( '.' ) {
47+ ext = new_ext;
48+ match ext {
49+ #[ cfg( feature = "json" ) ]
50+ "json" => {
51+ return DataFormat :: Json ;
52+ }
53+ #[ cfg( feature = "json" ) ]
54+ "jsonl" => {
55+ return DataFormat :: JsonLines ;
56+ }
57+ #[ cfg( feature = "term-svg" ) ]
58+ "term.svg" => {
59+ return Self :: TermSvg ;
60+ }
61+ _ => { }
62+ }
5763 }
64+ DataFormat :: Text
5865 }
5966}
6067
@@ -83,14 +90,14 @@ mod test {
8390 ( ".foo.txt" , DataFormat :: Text ) ,
8491 ( "foo.stdout.txt" , DataFormat :: Text ) ,
8592 ( "foo.json" , json) ,
86- ( "foo.stdout.json" , DataFormat :: Text ) ,
87- ( ".foo.json" , DataFormat :: Text ) ,
93+ ( "foo.stdout.json" , json ) ,
94+ ( ".foo.json" , json ) ,
8895 ( "foo.jsonl" , jsonl) ,
89- ( "foo.stdout.jsonl" , DataFormat :: Text ) ,
90- ( ".foo.jsonl" , DataFormat :: Text ) ,
96+ ( "foo.stdout.jsonl" , jsonl ) ,
97+ ( ".foo.jsonl" , jsonl ) ,
9198 ( "foo.term.svg" , term_svg) ,
92- ( "foo.stdout.term.svg" , DataFormat :: Text ) ,
93- ( ".foo.term.svg" , DataFormat :: Text ) ,
99+ ( "foo.stdout.term.svg" , term_svg ) ,
100+ ( ".foo.term.svg" , term_svg ) ,
94101 ] ;
95102 for ( input, output) in cases {
96103 let input = std:: path:: Path :: new ( input) ;
0 commit comments