Skip to content

Commit

Permalink
Add force-derive-default
Browse files Browse the repository at this point in the history
This option enforces the old behaviour around derive

Signed-off-by: Aaron Dewes <[email protected]>
  • Loading branch information
AaronDewes committed May 18, 2024
1 parent 50540a7 commit 251547f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ struct Kopium {
/// Type used to represent maps via additionalProperties
#[arg(long, value_enum, default_value_t)]
map_type: MapType,

/// Always add #[derive(Default)] to structs, even if it can't be derived without a manual impl for some fields
///
/// This option only has an effect if `--derive Default` is set.
#[arg(long)]
force_derive_default: bool,
}

#[derive(Clone, Copy, Debug, Subcommand)]
Expand Down Expand Up @@ -268,7 +274,7 @@ impl Kopium {
if derive.derived_trait == "JsonSchema" {
continue;
}
if derive.derived_trait == "Default" && !s.can_derive_default(&structs) {
if derive.derived_trait == "Default" && !self.force_derive_default && !s.can_derive_default(&structs) {
continue;
}
println!(r#"#[kube(derive="{}")]"#, derive.derived_trait);
Expand Down Expand Up @@ -356,7 +362,7 @@ impl Kopium {

for derive in &self.derive {
if derive.derived_trait == "Default" {
if !s.can_derive_default(containers) {
if !s.can_derive_default(containers) || (self.force_derive_default && !s.is_enum) {
continue;
}
}
Expand Down

0 comments on commit 251547f

Please sign in to comment.