Skip to content

Commit

Permalink
macro for columns
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Jul 30, 2024
1 parent 5e9ed0c commit 9f09f8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/get/cronjob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ impl Lister<ObjectListItem> for CronjobsLister {
}).map(|p| p.clone()).collect()))
}

// TODO - record last run and how many running (somehow)
fn print(&self, resources: Vec<ObjectListItem>) {
macro_rules! cols { () => ("{0: <10} {1: <10} {2: <10} {3: <10} {4: <10} {5: <10} {6: <15} {7: <10}") };
println!(
"{0: <10} {1: <10} {2: <10} {3: <10} {4: <10} {5: <10} {6: <15} {7: <10}",
cols!(),
"NAMESPACE", "NAME", "SCHEDULE", "TIMEZONE", "SUSPEND", "ACTIVE", "LAST SCHEDULE", "AGE"
);
let map = resources.iter().fold(HashMap::<NamespacedName, Vec<ObjectListItem>>::new(), |mut acc, item| {
Expand All @@ -36,8 +38,8 @@ impl Lister<ObjectListItem> for CronjobsLister {
let age = age(created);

println!(
"{0: <10} {1: <10} {2: <10} {3: <10} {4: <10} {5: <10} {6: <15} {7: <10}",
name.namespace, name.name, "TODO", timezone.unwrap_or("-".to_string()), "False", "-", "-", age
cols!(),
name.namespace, name.name, schedule, timezone.unwrap_or("<none>".to_string()), "False", "-", "-", age
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ pub fn hash_k8s_resource(obj: &mut (impl Metadata<Scope=NamespaceResourceScope,
hash
}

// age returns the age of a resource in a human-readable format, with only the first 2 resolutions (eg 2d1h4m becomes 2d1h)
// age returns the age of a resource in a human-readable format, with only the first segment of resolution (eg 2d1h4m becomes 2d)
pub fn age(date_time: DateTime<Local>) -> String {
match Local::now().signed_duration_since(date_time).to_std() {
Ok(age) => humantime::format_duration(age).to_string()
.split_whitespace().take(2).collect::<Vec<&str>>()
.split_whitespace().take(1).collect::<Vec<&str>>()
.join(""),
Err(_) => "".to_string()
}
Expand Down

0 comments on commit 9f09f8f

Please sign in to comment.