@@ -11,8 +11,8 @@ use std::env;
1111
1212#[ derive( StructOpt , Debug ) ]
1313struct Opt {
14- #[ structopt( name = "INPUT" ) ]
15- input : String ,
14+ #[ structopt( name = "INPUT" , required = true ) ]
15+ inputs : Vec < String > ,
1616 #[ structopt( long = "author" ) ]
1717 author : String ,
1818 #[ structopt( long = "project" ) ]
@@ -25,13 +25,6 @@ struct Opt {
2525
2626fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2727 let opt = Opt :: from_args ( ) ;
28- let license = create_license (
29- opt. input . as_str ( )
30- ) ;
31- let license = license. unwrap_or_else ( || {
32- eprintln ! ( "Not found match license: {}" , opt. input) ;
33- process:: exit ( 1 ) ;
34- } ) ;
3528 let dt = Local :: now ( ) ;
3629 let current_year = dt. year ( ) ;
3730 let year = opt. year . unwrap_or_else ( || {
@@ -48,17 +41,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4841 . into_string ( )
4942 . expect ( "use --project: Fail to unwrap os_string" )
5043 } ) ;
51-
52- let license_text = license. notice (
53- year,
54- & author,
55- & project) ;
5644 let output = opt. output . unwrap_or_else ( || {
57- "LICENSE" . to_string ( )
58- } ) ;
59- write_license ( & license_text, & output) . unwrap_or_else ( |error| {
60- eprintln ! ( "Can not write license text to \" {}\" : {}" , output, error) ;
61- process:: exit ( 1 ) ;
45+ "LICENSE" . to_string ( )
6246 } ) ;
47+ let multi_license = opt. inputs . len ( ) > 1 ;
48+
49+ opt. inputs
50+ . iter ( )
51+ . for_each ( |s| {
52+ let license = create_license ( s. as_str ( ) ) . unwrap_or_else ( || {
53+ eprintln ! ( "Not found match license: {}" , s) ;
54+ process:: exit ( 1 ) ;
55+ } ) ;
56+ let license_text = license. notice (
57+ year,
58+ & author,
59+ & project
60+ ) ;
61+ let output = if multi_license { format ! ( "{}_{}" , output, s. to_uppercase( ) ) }
62+ else { output. clone ( ) } ;
63+ write_license ( & license_text, & output) . unwrap_or_else ( |error| {
64+ eprintln ! ( "Can not write license text to \" {}\" : {}" , output, error) ;
65+ process:: exit ( 1 ) ;
66+ } ) ;
67+ } ) ;
6368 Ok ( ( ) )
6469}
0 commit comments