Skip to content

Commit

Permalink
status: support bootupctl status --json in container
Browse files Browse the repository at this point in the history
The output like:
```
bash-5.2# bootupctl status --json
{"components":["BIOS","EFI"]}
```
Fixes: #794
  • Loading branch information
HuijingHei committed Dec 6, 2024
1 parent de29ccf commit 4bbcb29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
set -xeuo pipefail
output=$(sudo podman run --rm -ti localhost/bootupd:latest bootupctl status | tr -d '\r')
[ "Available components: BIOS EFI" == "${output}" ]
output=$(sudo podman run --rm -ti localhost/bootupd:latest bootupctl status --json)
[ '{"components":["BIOS","EFI"]}' == "${output}" ]
- name: bootc install to disk
run: |
set -xeuo pipefail
Expand Down
15 changes: 12 additions & 3 deletions src/cli/bootupctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl CtlCommand {
/// Runner for `status` verb.
fn run_status(opts: StatusOpts) -> Result<()> {
if crate::util::running_in_container() {
return run_status_in_container();
return run_status_in_container(opts.json);
}
ensure_running_in_systemd()?;
let r = bootupd::status()?;
Expand Down Expand Up @@ -176,12 +176,21 @@ fn ensure_running_in_systemd() -> Result<()> {
}

/// If running in container, just print the available payloads
fn run_status_in_container() -> Result<()> {
fn run_status_in_container(json_format: bool) -> Result<()> {
let all_components = crate::bootupd::get_components();
if all_components.is_empty() {
return Ok(());
}
let avail: Vec<_> = all_components.keys().cloned().collect();
println!("Available components: {}", avail.join(" "));
if json_format {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
let output: serde_json::Value = serde_json::json!({
"components": avail
});
serde_json::to_writer(&mut stdout, &output)?;
} else {
println!("Available components: {}", avail.join(" "));
}
Ok(())
}

0 comments on commit 4bbcb29

Please sign in to comment.