Skip to content

Commit

Permalink
cli: Add a human readable format to status
Browse files Browse the repository at this point in the history
Adds a human-readable option to bootc status --format
and makes it default when running on a terminal.

Co-authored-by: Huijing Hei <[email protected]>
Co-authored-by: Yasmin de Souza <[email protected]>
Co-authored-by: Steven Presti <[email protected]>
Co-authored-by: Luke Yang <[email protected]>

Signed-off-by: Joseph Marrero <[email protected]>
  • Loading branch information
jmarrero committed Jul 26, 2024
1 parent cf6c028 commit b165c19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub(crate) struct EditOpts {
#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
#[clap(rename_all = "lowercase")]
pub(crate) enum OutputFormat {
/// Output in Human Readable format.
HumanReadable,
/// Output in YAML format.
Yaml,
/// Output in JSON format.
Expand Down
15 changes: 14 additions & 1 deletion lib/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::VecDeque;
use std::io::IsTerminal;

use anyhow::{Context, Result};
use camino::Utf8Path;
Expand Down Expand Up @@ -305,12 +306,24 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
let legacy_opt = if opts.json {
OutputFormat::Json
} else {
OutputFormat::Yaml
if std::io::stdout().is_terminal() {
OutputFormat::HumanReadable
} else {
OutputFormat::Yaml
}
};
let format = opts.format.unwrap_or(legacy_opt);
match format {
OutputFormat::Json => serde_json::to_writer(&mut out, &host).map_err(anyhow::Error::new),
OutputFormat::Yaml => serde_yaml::to_writer(&mut out, &host).map_err(anyhow::Error::new),
OutputFormat::HumanReadable => {
if let Some(booted) = host.status.booted {
println!("Current deployment image: {:?}", booted.image.unwrap().image.image);
} else {
println!("Not on a bootc host");
}
Ok(())
}
}
.context("Writing to stdout")?;

Expand Down

0 comments on commit b165c19

Please sign in to comment.