@@ -4,67 +4,60 @@ use graphql_client_codegen::{
4
4
} ;
5
5
use std:: fs:: File ;
6
6
use std:: io:: Write as IoWrite ;
7
- use std:: path:: { Path , PathBuf } ;
7
+ use std:: path:: PathBuf ;
8
8
use syn;
9
9
10
- # [ allow ( clippy :: too_many_arguments ) ]
11
- pub fn generate_code (
12
- query_path : PathBuf ,
13
- schema_path : & Path ,
14
- module_name : String ,
15
- selected_operation : Option < String > ,
16
- additional_derives : Option < String > ,
17
- deprecation_strategy : Option < & str > ,
18
- no_formatting : bool ,
19
- module_visibility : Option < & str > ,
20
- output : & Path ,
21
- ) -> Result < ( ) , failure:: Error > {
22
- let deprecation_strategy = match deprecation_strategy {
10
+ pub ( crate ) struct CliCodegenParams {
11
+ pub query_path : PathBuf ,
12
+ pub schema_path : PathBuf ,
13
+ pub selected_operation : Option < String > ,
14
+ pub additional_derives : Option < String > ,
15
+ pub deprecation_strategy : Option < String > ,
16
+ pub no_formatting : bool ,
17
+ pub module_visibility : Option < String > ,
18
+ pub output : PathBuf ,
19
+ }
20
+
21
+ pub ( crate ) fn generate_code ( params : CliCodegenParams ) -> Result < ( ) , failure:: Error > {
22
+ let deprecation_strategy = match params . deprecation_strategy . as_ref ( ) . map ( |s| s . as_str ( ) ) {
23
23
Some ( "allow" ) => Some ( deprecation:: DeprecationStrategy :: Allow ) ,
24
24
Some ( "deny" ) => Some ( deprecation:: DeprecationStrategy :: Deny ) ,
25
25
Some ( "warn" ) => Some ( deprecation:: DeprecationStrategy :: Warn ) ,
26
26
_ => None ,
27
27
} ;
28
28
29
- let module_visibility = match module_visibility {
30
- Some ( "pub" ) => syn:: VisPublic {
31
- pub_token : <Token ! [ pub ] >:: default ( ) ,
32
- }
33
- . into ( ) ,
34
- Some ( "private" ) => syn:: Visibility :: Inherited { } ,
35
- _ => syn:: VisPublic {
29
+ let mut options = GraphQLClientCodegenOptions :: new_default ( ) ;
30
+
31
+ // options.set_module_name(module_name);
32
+ options. set_module_visibility (
33
+ syn:: VisPublic {
36
34
pub_token : <Token ! [ pub ] >:: default ( ) ,
37
35
}
38
36
. into ( ) ,
39
- } ;
40
-
41
- let mut options = GraphQLClientCodegenOptions :: new_default ( ) ;
42
-
43
- options. set_module_name ( module_name) ;
44
- options. set_module_visibility ( module_visibility) ;
37
+ ) ;
45
38
46
- if let Some ( selected_operation) = selected_operation {
39
+ if let Some ( selected_operation) = params . selected_operation {
47
40
options. set_operation_name ( selected_operation) ;
48
41
}
49
42
50
- if let Some ( additional_derives) = additional_derives {
43
+ if let Some ( additional_derives) = params . additional_derives {
51
44
options. set_additional_derives ( additional_derives) ;
52
45
}
53
46
54
47
if let Some ( deprecation_strategy) = deprecation_strategy {
55
48
options. set_deprecation_strategy ( deprecation_strategy) ;
56
49
}
57
50
58
- let gen = generate_module_token_stream ( query_path, & schema_path, options) ?;
51
+ let gen = generate_module_token_stream ( params . query_path , & params . schema_path , options) ?;
59
52
60
53
let generated_code = gen. to_string ( ) ;
61
- let generated_code = if cfg ! ( feature = "rustfmt" ) && !no_formatting {
54
+ let generated_code = if cfg ! ( feature = "rustfmt" ) && !params . no_formatting {
62
55
format ( & generated_code)
63
56
} else {
64
57
generated_code
65
58
} ;
66
59
67
- let mut file = File :: create ( output) ?;
60
+ let mut file = File :: create ( params . output ) ?;
68
61
69
62
write ! ( file, "{}" , generated_code) ?;
70
63
0 commit comments