@@ -4,10 +4,11 @@ extern crate quicli;
4
4
use quicli:: prelude:: * ;
5
5
use std:: collections:: { HashMap , HashSet } ;
6
6
use std:: fs:: { self , File } ;
7
- use std:: io:: prelude:: * ;
8
7
use std:: io:: Write ;
8
+ use std:: io:: { self , prelude:: * } ;
9
9
use std:: path:: { Path , PathBuf } ;
10
10
use std:: process:: Command ;
11
+ use structopt:: StructOpt ;
11
12
12
13
#[ derive( Debug ) ]
13
14
struct ExampleEvent {
@@ -40,9 +41,9 @@ struct Cli {
40
41
/// Overwrite existing files
41
42
#[ structopt( long = "overwrite" ) ]
42
43
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 ,
46
47
}
47
48
48
49
fn get_ignorelist ( ) -> HashSet < String > {
@@ -98,7 +99,7 @@ fn write_mod_index(
98
99
mod_path : & Path ,
99
100
parsed_files : & [ ParsedEventFile ] ,
100
101
overwrite : bool ,
101
- ) -> Result < ( ) > {
102
+ ) -> io :: Result < ( ) > {
102
103
if overwrite_warning ( mod_path, overwrite) . is_none ( ) {
103
104
let mut mod_content: Vec < String > = Vec :: new ( ) ;
104
105
for parsed in parsed_files {
@@ -127,7 +128,7 @@ fn write_cargo_features(
127
128
cargo_path : & Path ,
128
129
parsed_files : & [ ParsedEventFile ] ,
129
130
overwrite : bool ,
130
- ) -> Result < ( ) > {
131
+ ) -> Result < ( ) , Error > {
131
132
if overwrite_warning ( cargo_path, overwrite) . is_none ( ) {
132
133
let buf = std:: fs:: read_to_string ( cargo_path) ?;
133
134
let mut doc = buf. parse :: < toml_edit:: Document > ( ) ?;
@@ -163,7 +164,7 @@ fn write_cargo_features(
163
164
Ok ( ( ) )
164
165
}
165
166
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 < ( ) > {
167
168
if overwrite_warning ( readme_path, overwrite) . is_none ( ) {
168
169
let version_text = format ! (
169
170
"Generated from commit [{}](https://github.com/aws/aws-lambda-go/commit/{})." ,
@@ -188,7 +189,7 @@ fn fuzz(string: &mut String) {
188
189
string. retain ( |c| c != '_' && c != '-' )
189
190
}
190
191
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 > {
192
193
let mut listing = HashMap :: new ( ) ;
193
194
for entry in fs:: read_dir ( dir_path) ? {
194
195
let entry = entry?;
@@ -507,7 +508,7 @@ fn read_example_event(test_fixture: &Path) -> String {
507
508
contents
508
509
}
509
510
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 < ( ) > {
511
512
// Write the example event to the output location.
512
513
let full = out_dir. join ( "fixtures" ) . join ( & example_event. name ) ;
513
514
{
@@ -525,7 +526,7 @@ fn write_fixture(example_event: &ExampleEvent, out_dir: &Path, overwrite: bool)
525
526
Ok ( ( ) )
526
527
}
527
528
528
- fn generate_test_module ( example_events : & [ ExampleEvent ] ) -> Result < codegen:: Module > {
529
+ fn generate_test_module ( example_events : & [ ExampleEvent ] ) -> io :: Result < codegen:: Module > {
529
530
let mut test_module = codegen:: Module :: new ( "test" ) ;
530
531
test_module. annotation ( vec ! [ "cfg(test)" ] ) ;
531
532
test_module. import ( "super" , "*" ) ;
@@ -577,7 +578,10 @@ fn generate_test_function(
577
578
test_function
578
579
}
579
580
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
+
581
585
let mut parsed_files: Vec < ParsedEventFile > = Vec :: new ( ) ;
582
586
583
587
// 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| {
680
684
if let Some ( cargo_path) = find_cargo_file ( & args. output_location ) {
681
685
write_cargo_features ( & cargo_path, & parsed_files, args. overwrite ) ?;
682
686
}
683
- } ) ;
687
+
688
+ Ok ( ( ) )
689
+ }
684
690
685
691
fn find_cargo_file ( base : & Path ) -> Option < PathBuf > {
686
692
if let Some ( path) = base. parent ( ) {
0 commit comments