Skip to content

Commit 5b881b4

Browse files
committed
status: Output targeted message in non-bootc case, update docs
- Output a clear message when we're not booted - Update the docs and help to reflect current reality (e.g. format is stable) and include some guidance on use cases Signed-off-by: Colin Walters <[email protected]>
1 parent 4621d76 commit 5b881b4

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/src/cli.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,19 @@ pub(crate) enum Opt {
369369
Edit(EditOpts),
370370
/// Display status
371371
///
372-
/// This will output a YAML-formatted object using a schema intended to match a Kubernetes resource
373-
/// that describes the state of the booted system.
372+
/// If standard output is a terminal, this will output a description of the bootc system state.
373+
/// If standard output is not a terminal, output a YAML-formatted object using a schema
374+
/// intended to match a Kubernetes resource that describes the state of the booted system.
374375
///
375-
/// The exact API format is not currently declared stable.
376+
/// ## Parsing output via programs
377+
///
378+
/// Either the default YAML format or `--format=json` can be used. Do not attempt to
379+
/// explicitly parse the output of `--format=humanreadable` as it will very likely
380+
/// change over time.
381+
///
382+
/// ## Programmatically detecting whether the system is deployed via bootc
383+
///
384+
/// Invoke e.g. `bootc status --json`, and check if `status.booted` is not `null`.
376385
Status(StatusOpts),
377386
/// Adds a transient writable overlayfs on `/usr` that will be discarded on reboot.
378387
///

lib/src/status.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ fn human_render_ostree(mut out: impl Write, slot_name: &str, _ostree_commit: &st
364364
Ok(())
365365
}
366366

367-
/// Implementation of rendering our host structure in a "human readable" way.
368-
fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
367+
fn human_readable_output_booted(mut out: impl Write, host: &Host) -> Result<()> {
369368
for (slot_name, status) in [
370369
("staged", &host.status.staged),
371370
("booted", &host.status.booted),
@@ -386,6 +385,16 @@ fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
386385
Ok(())
387386
}
388387

388+
/// Implementation of rendering our host structure in a "human readable" way.
389+
fn human_readable_output(mut out: impl Write, host: &Host) -> Result<()> {
390+
if host.status.booted.is_some() {
391+
human_readable_output_booted(out, host)?;
392+
} else {
393+
writeln!(out, "System is not deployed via bootc.")?;
394+
}
395+
Ok(())
396+
}
397+
389398
#[cfg(test)]
390399
mod tests {
391400
use super::*;
@@ -465,15 +474,7 @@ mod tests {
465474
// staged/rollback image, no booted
466475
let w = human_status_from_spec_fixture(include_str!("fixtures/spec-staged-rollback.yaml"))
467476
.expect("No spec found");
468-
let expected = indoc::indoc! { r"
469-
Current staged image: quay.io/example/someimage:latest
470-
Image version: nightly (2023-10-14 19:22:15 UTC)
471-
Image digest: sha256:16dc2b6256b4ff0d2ec18d2dbfb06d117904010c8cf9732cdb022818cf7a7566
472-
No booted image present
473-
Current rollback image: quay.io/example/someimage:latest
474-
Image version: nightly (2023-09-30 19:22:16 UTC)
475-
Image digest: sha256:736b359467c9437c1ac915acaae952aad854e07eb4a16a94999a48af08c83c34
476-
"};
477+
let expected = "System is not deployed via bootc.\n";
477478
similar_asserts::assert_eq!(w, expected);
478479
}
479480

0 commit comments

Comments
 (0)