Skip to content

Commit

Permalink
conditionally render status line
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Hoß <[email protected]>
  • Loading branch information
sebhoss committed Mar 16, 2024
1 parent 561adae commit c777f10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::PathBuf;
#[macro_use] extern crate log;
#[macro_use]
extern crate log;
use anyhow::{anyhow, Context, Result};
use clap::{CommandFactory, Parser, Subcommand};
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::{
Expand Down Expand Up @@ -222,8 +223,8 @@ impl Kopium {
if scope == "Namespaced" {
println!(r#"#[kube(namespaced)]"#);
}
if let Some(CustomResourceSubresources { status: Some(_), .. }) =
version.subresources
if version.subresources.is_some_and(|c| c.status.is_some())
&& self.has_status_resource(&structs)
{
println!(r#"#[kube(status = "{}Status")]"#, kind);
}
Expand Down Expand Up @@ -327,6 +328,12 @@ impl Kopium {
println!("#[derive({})]", derives.join(", "));
}

fn has_status_resource(&self, results: &[Container]) -> bool {
results
.iter()
.any(|o| o.is_status_container() && !o.members.is_empty())
}

fn print_prelude(&self, results: &[Container]) {
if !self.hide_kube {
println!("use kube::CustomResource;");
Expand Down
4 changes: 4 additions & 0 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl Container {
self.level == 1 && self.name.ends_with("Spec")
}

pub fn is_status_container(&self) -> bool {
self.level == 1 && self.name.ends_with("Status")
}

pub fn contains_conditions(&self) -> bool {
self.members.iter().any(|m| m.type_.contains("Vec<Condition>"))
}
Expand Down

0 comments on commit c777f10

Please sign in to comment.