File tree 3 files changed +18
-16
lines changed
3 files changed +18
-16
lines changed Original file line number Diff line number Diff line change @@ -392,22 +392,14 @@ macro_rules! create_config {
392
392
}
393
393
394
394
fn set_license_template( & mut self ) {
395
- if !self . was_set( ) . license_template_path( ) {
396
- return ;
395
+ if self . was_set( ) . license_template_path( ) {
396
+ let lt_path = self . license_template_path( ) ;
397
+ match license:: load_and_compile_template( & lt_path) {
398
+ Ok ( re) => self . license_template = Some ( re) ,
399
+ Err ( msg) => eprintln!( "Warning for license template file {:?}: {}" ,
400
+ lt_path, msg) ,
401
+ }
397
402
}
398
- let lt_path = self . license_template_path( ) ;
399
- let try = || -> Result <Regex , LicenseError > {
400
- let mut lt_file = File :: open( & lt_path) ?;
401
- let mut lt_str = String :: new( ) ;
402
- lt_file. read_to_string( & mut lt_str) ?;
403
- let lt_parsed = TemplateParser :: parse( & lt_str) ?;
404
- Ok ( Regex :: new( & lt_parsed) ?)
405
- } ;
406
- match try( ) {
407
- Ok ( re) => self . license_template = Some ( re) ,
408
- Err ( msg) => eprintln!( "Warning for license template file {:?}: {}" ,
409
- lt_path, msg) ,
410
- } ;
411
403
}
412
404
}
413
405
Original file line number Diff line number Diff line change @@ -37,7 +37,6 @@ pub mod license;
37
37
38
38
use config_type:: ConfigType ;
39
39
use file_lines:: FileLines ;
40
- use license:: { LicenseError , TemplateParser } ;
41
40
pub use lists:: * ;
42
41
pub use options:: * ;
43
42
use summary:: Summary ;
Original file line number Diff line number Diff line change 1
1
use std:: io;
2
2
use std:: fmt;
3
+ use std:: fs:: File ;
4
+ use std:: io:: Read ;
3
5
4
6
use regex;
7
+ use regex:: Regex ;
5
8
6
9
#[ derive( Debug ) ]
7
10
pub enum LicenseError {
@@ -210,6 +213,14 @@ impl TemplateParser {
210
213
}
211
214
}
212
215
216
+ pub fn load_and_compile_template ( path : & str ) -> Result < Regex , LicenseError > {
217
+ let mut lt_file = File :: open ( & path) ?;
218
+ let mut lt_str = String :: new ( ) ;
219
+ lt_file. read_to_string ( & mut lt_str) ?;
220
+ let lt_parsed = TemplateParser :: parse ( & lt_str) ?;
221
+ Ok ( Regex :: new ( & lt_parsed) ?)
222
+ }
223
+
213
224
#[ cfg( test) ]
214
225
mod test {
215
226
use super :: TemplateParser ;
You can’t perform that action at this time.
0 commit comments