@@ -12,6 +12,7 @@ use crate::{
12
12
postprocessing:: Postprocessor ,
13
13
template,
14
14
types:: Types ,
15
+ GenerateFlags ,
15
16
} ;
16
17
17
18
#[ derive( Default , Deserialize ) ]
@@ -29,7 +30,7 @@ pub(crate) fn generate(
29
30
types : Types ,
30
31
tpl_name : String ,
31
32
output_dir : & Utf8Path ,
32
- no_postprocess : bool ,
33
+ flags : GenerateFlags ,
33
34
) -> anyhow:: Result < ( ) > {
34
35
let ( name_without_jinja_suffix, tpl_path) = match tpl_name. strip_suffix ( ".jinja" ) {
35
36
Some ( basename) => ( basename, & tpl_name) ,
@@ -70,7 +71,7 @@ pub(crate) fn generate(
70
71
tpl_file_ext,
71
72
output_dir,
72
73
postprocessor : & postprocessor,
73
- no_postprocess ,
74
+ flags ,
74
75
} ;
75
76
76
77
match tpl_kind {
@@ -80,7 +81,7 @@ pub(crate) fn generate(
80
81
TemplateKind :: Summary => generator. generate_summary ( types, api) ?,
81
82
}
82
83
83
- if !no_postprocess {
84
+ if !flags . no_postprocess {
84
85
postprocessor. run_postprocessor ( ) ;
85
86
}
86
87
@@ -92,7 +93,7 @@ struct Generator<'a> {
92
93
tpl_file_ext : & ' a str ,
93
94
output_dir : & ' a Utf8Path ,
94
95
postprocessor : & ' a Postprocessor ,
95
- no_postprocess : bool ,
96
+ flags : GenerateFlags ,
96
97
}
97
98
98
99
impl Generator < ' _ > {
@@ -172,11 +173,15 @@ impl Generator<'_> {
172
173
} ;
173
174
174
175
let file_path = self . output_dir . join ( format ! ( "{basename}.{tpl_file_ext}" ) ) ;
176
+
177
+ if self . flags . create_file_parents && !self . output_dir . exists ( ) {
178
+ fs:: create_dir_all ( self . output_dir ) ?;
179
+ }
175
180
let out_file = BufWriter :: new ( File :: create ( & file_path) ?) ;
176
181
177
182
self . tpl . render_to_write ( ctx, out_file) ?;
178
183
179
- if !self . no_postprocess {
184
+ if !self . flags . no_postprocess {
180
185
self . postprocessor . add_path ( & file_path) ;
181
186
}
182
187
0 commit comments