@@ -4,10 +4,11 @@ extern crate quicli;
44use quicli:: prelude:: * ;
55use std:: collections:: { HashMap , HashSet } ;
66use std:: fs:: { self , File } ;
7- use std:: io:: prelude:: * ;
87use std:: io:: Write ;
8+ use std:: io:: { self , prelude:: * } ;
99use std:: path:: { Path , PathBuf } ;
1010use std:: process:: Command ;
11+ use structopt:: StructOpt ;
1112
1213#[ derive( Debug ) ]
1314struct ExampleEvent {
@@ -40,9 +41,9 @@ struct Cli {
4041 /// Overwrite existing files
4142 #[ structopt( long = "overwrite" ) ]
4243 overwrite : bool ,
43- /// Verbose output. Pass many times for more log output
44- #[ structopt( long = "verbose" , short = "v" , parse ( from_occurrences ) ) ]
45- verbosity : u8 ,
44+
45+ #[ structopt( flatten ) ]
46+ verbose : Verbosity ,
4647}
4748
4849fn get_ignorelist ( ) -> HashSet < String > {
@@ -98,7 +99,7 @@ fn write_mod_index(
9899 mod_path : & Path ,
99100 parsed_files : & [ ParsedEventFile ] ,
100101 overwrite : bool ,
101- ) -> Result < ( ) > {
102+ ) -> io :: Result < ( ) > {
102103 if overwrite_warning ( mod_path, overwrite) . is_none ( ) {
103104 let mut mod_content: Vec < String > = Vec :: new ( ) ;
104105 for parsed in parsed_files {
@@ -127,7 +128,7 @@ fn write_cargo_features(
127128 cargo_path : & Path ,
128129 parsed_files : & [ ParsedEventFile ] ,
129130 overwrite : bool ,
130- ) -> Result < ( ) > {
131+ ) -> Result < ( ) , Error > {
131132 if overwrite_warning ( cargo_path, overwrite) . is_none ( ) {
132133 let buf = std:: fs:: read_to_string ( cargo_path) ?;
133134 let mut doc = buf. parse :: < toml_edit:: Document > ( ) ?;
@@ -163,7 +164,7 @@ fn write_cargo_features(
163164 Ok ( ( ) )
164165}
165166
166- fn write_readme ( readme_path : & Path , git_hash : & str , overwrite : bool ) -> Result < ( ) > {
167+ fn write_readme ( readme_path : & Path , git_hash : & str , overwrite : bool ) -> io :: Result < ( ) > {
167168 if overwrite_warning ( readme_path, overwrite) . is_none ( ) {
168169 let version_text = format ! (
169170 "Generated from commit [{}](https://github.com/aws/aws-lambda-go/commit/{})." ,
@@ -188,7 +189,7 @@ fn fuzz(string: &mut String) {
188189 string. retain ( |c| c != '_' && c != '-' )
189190}
190191
191- fn get_fuzzy_file_listing ( dir_path : & Path ) -> Result < HashMap < String , PathBuf > > {
192+ fn get_fuzzy_file_listing ( dir_path : & Path ) -> Result < HashMap < String , PathBuf > , Error > {
192193 let mut listing = HashMap :: new ( ) ;
193194 for entry in fs:: read_dir ( dir_path) ? {
194195 let entry = entry?;
@@ -507,7 +508,7 @@ fn read_example_event(test_fixture: &Path) -> String {
507508 contents
508509}
509510
510- fn write_fixture ( example_event : & ExampleEvent , out_dir : & Path , overwrite : bool ) -> Result < ( ) > {
511+ fn write_fixture ( example_event : & ExampleEvent , out_dir : & Path , overwrite : bool ) -> io :: Result < ( ) > {
511512 // Write the example event to the output location.
512513 let full = out_dir. join ( "fixtures" ) . join ( & example_event. name ) ;
513514 {
@@ -525,7 +526,7 @@ fn write_fixture(example_event: &ExampleEvent, out_dir: &Path, overwrite: bool)
525526 Ok ( ( ) )
526527}
527528
528- fn generate_test_module ( example_events : & [ ExampleEvent ] ) -> Result < codegen:: Module > {
529+ fn generate_test_module ( example_events : & [ ExampleEvent ] ) -> io :: Result < codegen:: Module > {
529530 let mut test_module = codegen:: Module :: new ( "test" ) ;
530531 test_module. annotation ( vec ! [ "cfg(test)" ] ) ;
531532 test_module. import ( "super" , "*" ) ;
@@ -577,7 +578,10 @@ fn generate_test_function(
577578 test_function
578579}
579580
580- main ! ( |args: Cli , log_level: verbosity| {
581+ fn main ( ) -> CliResult {
582+ let args = Cli :: from_args ( ) ;
583+ args. verbose . setup_env_logger ( env ! ( "CARGO_PKG_NAME" ) ) ?;
584+
581585 let mut parsed_files: Vec < ParsedEventFile > = Vec :: new ( ) ;
582586
583587 // The glob pattern we are going to use to find the go files with event defs.
@@ -680,7 +684,9 @@ main!(|args: Cli, log_level: verbosity| {
680684 if let Some ( cargo_path) = find_cargo_file ( & args. output_location ) {
681685 write_cargo_features ( & cargo_path, & parsed_files, args. overwrite ) ?;
682686 }
683- } ) ;
687+
688+ Ok ( ( ) )
689+ }
684690
685691fn find_cargo_file ( base : & Path ) -> Option < PathBuf > {
686692 if let Some ( path) = base. parent ( ) {
0 commit comments