added info of architecture and size of images

This commit is contained in:
Thomas Eppers 2021-09-23 22:48:19 +02:00
parent 67486f0042
commit 7828d7c703

View File

@ -3,13 +3,19 @@ use std::fmt;
use chrono::DateTime; use chrono::DateTime;
use serde::Deserialize; use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
struct ImageDetails { struct ImageDetails {
architecture: String, architecture: String,
os: String, // os: String,
size: usize, size: usize,
} }
impl fmt::Display for ImageDetails {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}, {}MB]", self.architecture, self.size / 1024 / 1024)
}
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Images { pub struct Images {
images: Vec<ImageDetails>, images: Vec<ImageDetails>,
@ -117,10 +123,22 @@ impl Tags {
impl fmt::Display for Images { impl fmt::Display for Images {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//architecture infos
let mut arch = String::new();
for image in &self.images {
arch.push_str(&format!("{}", image));
}
let now = chrono::Utc::now(); let now = chrono::Utc::now();
let rfc3339 = DateTime::parse_from_rfc3339(&self.last_updated).unwrap(); let rfc3339 = DateTime::parse_from_rfc3339(&self.last_updated).unwrap();
let dif = now - rfc3339.with_timezone(&chrono::Utc); let dif = now - rfc3339.with_timezone(&chrono::Utc);
write!(f, "{} vor {}", self.tag_name, format_time_nice(dif)) write!(
f,
"{} vor {} {}",
self.tag_name,
format_time_nice(dif),
arch
)
} }
} }