Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status: support bootupctl status --json in container #795

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
Loading