@@ -105,6 +105,10 @@ struct Kopium {
105
105
#[ structopt( long, short = "d" ) ]
106
106
docs : bool ,
107
107
108
+ /// Emit builder derives via the typed_builder crate
109
+ #[ structopt( long, short = "b" ) ]
110
+ builders : bool ,
111
+
108
112
/// Schema mode to use for kube-derive
109
113
///
110
114
/// The default is --schema=disabled and will compile without a schema,
@@ -293,6 +297,15 @@ impl Kopium {
293
297
format_ident ! ( "{}" , name)
294
298
} ;
295
299
let spec_trimmed_type = m. type_ . as_str ( ) . replace ( & format ! ( "{}Spec" , kind) , & kind) ;
300
+ if self . builders {
301
+ if spec_trimmed_type. starts_with ( "Option" ) {
302
+ println ! ( "#[builder(default, setter(strip_option))]" ) ;
303
+ } else if spec_trimmed_type. starts_with ( "Vec" )
304
+ || spec_trimmed_type. starts_with ( "BTreeMap" )
305
+ {
306
+ println ! ( "#[builder(default)]" ) ;
307
+ }
308
+ }
296
309
println ! ( " pub {}: {}," , safe_name, spec_trimmed_type) ;
297
310
}
298
311
println ! ( "}}" ) ;
@@ -346,6 +359,9 @@ impl Kopium {
346
359
// CustomResource first for root struct
347
360
derives. insert ( 0 , "CustomResource" . to_string ( ) ) ;
348
361
}
362
+ if self . builders {
363
+ derives. push ( "TypedBuilder" . to_string ( ) ) ;
364
+ }
349
365
derives. extend ( self . derive . clone ( ) ) ; // user derives last in user order
350
366
println ! ( "#[derive({})]" , derives. join( ", " ) ) ;
351
367
}
@@ -358,6 +374,9 @@ impl Kopium {
358
374
if !self . hide_kube {
359
375
println ! ( "use kube::CustomResource;" ) ;
360
376
}
377
+ if self . builders {
378
+ println ! ( "use typed_builder::TypedBuilder;" ) ;
379
+ }
361
380
if self . derive . contains ( & "JsonSchema" . to_string ( ) ) {
362
381
println ! ( "use schemars::JsonSchema;" ) ;
363
382
}
0 commit comments