Skip to content
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default-members = [
resolver = "2"

[workspace.package]
version = "0.1.3"
version = "0.1.4"
edition = "2024"
license = "Apache-2.0"
rust-version = "1.88"
Expand Down
70 changes: 57 additions & 13 deletions apps/bootable-tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ enum Commands {
index: usize,
#[arg(long, value_name = "ISO_FILE")]
output: Option<PathBuf>,
/// Emit newline-delimited JSON progress for graphical clients.
#[arg(long)]
json_progress: bool,
},
/// List official Raspberry Pi Imager images.
PiImages {
Expand Down Expand Up @@ -174,7 +177,8 @@ fn main() -> Result<()> {
slug,
index,
output,
}) => download_release(&engine, &slug, index, output),
json_progress,
}) => download_release(&engine, &slug, index, output, json_progress),
Some(Commands::PiImages {
device,
limit,
Expand Down Expand Up @@ -290,19 +294,37 @@ fn download_release(
slug: &str,
index: usize,
output: Option<PathBuf>,
json_progress: bool,
) -> Result<()> {
let details = engine.distribution_details(slug)?;
let releases = resolve_releases(engine, &details)?;
let release = releases
.get(index)
.with_context(|| format!("release index {index} is out of range"))?;
let destination = output.unwrap_or_else(|| PathBuf::from(&release.name));
let mut reporter = ProgressReporter::default();
let report = engine.download_iso(release, &destination, |progress| reporter.print(progress))?;
println!("Ready to write: {}", report.path.display());
println!("Kind: {}", report.kind);
println!("Size: {}", format_bytes(report.size));
Ok(())
let mut reporter = ProgressReporter::new(json_progress);
let result = (|| {
let details = engine.distribution_details(slug)?;
let releases = resolve_releases(engine, &details)?;
let release = releases
.get(index)
.with_context(|| format!("release index {index} is out of range"))?;
let destination = output.unwrap_or_else(|| PathBuf::from(&release.name));
engine
.download_iso(release, &destination, |progress| reporter.print(progress))
.map_err(anyhow::Error::from)
})();

match result {
Ok(report) => {
if json_progress {
reporter.finished();
} else {
println!("Ready to write: {}", report.path.display());
println!("Kind: {}", report.kind);
println!("Size: {}", format_bytes(report.size));
}
Ok(())
}
Err(error) => {
reporter.failed(&error.to_string());
Err(error)
}
}
}

fn resolve_releases(engine: &Bootable, details: &DistributionDetails) -> Result<Vec<IsoRelease>> {
Expand Down Expand Up @@ -5079,6 +5101,28 @@ mod layout_tests {
));
}

#[test]
fn download_json_progress_is_an_explicit_client_mode() {
let cli = Cli::try_parse_from([
"bootable",
"download",
"cachyos",
"--index",
"1",
"--output",
"image.iso",
"--json-progress",
])
.expect("valid catalog client invocation");
assert!(matches!(
cli.command,
Some(Commands::Download {
json_progress: true,
..
})
));
}

#[test]
fn progress_events_are_stable_newline_json_payloads() {
let event = progress_event_json(&Progress {
Expand Down
2 changes: 1 addition & 1 deletion packaging/Packager.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "bootable"
product-name = "Bootable"
identifier = "app.bootable.Bootable"
version = "0.1.3"
version = "0.1.4"
description = "Create verified boot media from trusted images"
long-description = "A safety-first boot media writer with matching desktop and terminal interfaces."
homepage = "https://github.com/debpalash/bootable"
Expand Down
Loading