Skip to content

Commit 11508eb

Browse files
committed
status: Factor out helpers for rendering container image
Prep for more work; no functional changes. Signed-off-by: Colin Walters <[email protected]>
1 parent 3f11c4f commit 11508eb

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

lib/src/status.rs

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,46 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
325325
Ok(())
326326
}
327327

328+
/// Write the data for a container image based status.
329+
fn human_render_imagestatus(
330+
mut out: impl Write,
331+
slot_name: &str,
332+
image: &crate::spec::ImageStatus,
333+
) -> Result<()> {
334+
let transport = &image.image.transport;
335+
let imagename = &image.image.image;
336+
// Registry is the default, so don't show that
337+
let imageref = if transport == "registry" {
338+
Cow::Borrowed(imagename)
339+
} else {
340+
// But for non-registry we include the transport
341+
Cow::Owned(format!("{transport}:{imagename}"))
342+
};
343+
writeln!(out, "Current {slot_name} image: {imageref}")?;
344+
345+
let version = image
346+
.version
347+
.as_deref()
348+
.unwrap_or("No image version defined");
349+
let timestamp = image
350+
.timestamp
351+
.as_ref()
352+
.map(|t| t.to_string())
353+
.unwrap_or_else(|| "No timestamp present".to_owned());
354+
let digest = &image.image_digest;
355+
356+
writeln!(out, " Image version: {version} ({timestamp})")?;
357+
writeln!(out, " Image digest: {digest}")?;
358+
Ok(())
359+
}
360+
361+
fn human_render_ostree(mut out: impl Write, slot_name: &str, _ostree_commit: &str) -> Result<()> {
362+
// TODO consider rendering more ostree stuff here like rpm-ostree status does
363+
writeln!(out, "Current {slot_name} state is native ostree")?;
364+
Ok(())
365+
}
366+
367+
/// Implementation of rendering our host structure in a "human readable" way.
328368
fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
329369
for (slot_name, status) in [
330370
("staged", &host.status.staged),
@@ -333,32 +373,11 @@ fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
333373
] {
334374
if let Some(host_status) = status {
335375
if let Some(image) = &host_status.image {
336-
let transport = &image.image.transport;
337-
let imagename = &image.image.image;
338-
// Registry is the default, so don't show that
339-
let imageref = if transport == "registry" {
340-
Cow::Borrowed(imagename)
341-
} else {
342-
// But for non-registry we include the transport
343-
Cow::Owned(format!("{transport}:{imagename}"))
344-
};
345-
writeln!(out, "Current {slot_name} image: {imageref}")?;
346-
347-
let version = image
348-
.version
349-
.as_deref()
350-
.unwrap_or("No image version defined");
351-
let timestamp = image
352-
.timestamp
353-
.as_ref()
354-
.map(|t| t.to_string())
355-
.unwrap_or_else(|| "No timestamp present".to_owned());
356-
let digest = &image.image_digest;
357-
358-
writeln!(out, " Image version: {version} ({timestamp})")?;
359-
writeln!(out, " Image digest: {digest}")?;
376+
human_render_imagestatus(&mut out, slot_name, image)?;
377+
} else if let Some(ostree) = host_status.ostree.as_ref() {
378+
human_render_ostree(&mut out, slot_name, &ostree.checksum)?;
360379
} else {
361-
writeln!(out, "Current {slot_name} state is native ostree")?;
380+
writeln!(out, "Current {slot_name} state is unknown")?;
362381
}
363382
} else {
364383
writeln!(out, "No {slot_name} image present")?;

0 commit comments

Comments
 (0)