docs: document the library/CLI output split
CI / Test (push) Successful in 3m5s
CI / Check (push) Successful in 2m38s
CI / Format (push) Successful in 17s
CI / Clippy (push) Successful in 2m34s

The library is terminal-silent: diagnostics through the log facade,
progress through Progress sinks. The CLI owns all rendering.
This commit is contained in:
2026-10-03 00:13:34 +02:00
parent fe0b99ee6b
commit 57367faa01
2 changed files with 25 additions and 7 deletions
+4 -4
View File
@@ -18,7 +18,7 @@ ecr fedora # any Docker Hub image
## Library
`ecr` is a cargo workspace: `crates/ecr` is the library crate (package `ecr`), `crates/ecr-cli` the thin command-line front-end. Rust consumers can use the library directly — resolve an image, download it through the content cache, and run commands with a fully caller-controlled environment, bind targets and architecture:
`ecr` is a cargo workspace: `crates/ecr` is the library crate (package `ecr`), `crates/ecr-cli` the thin command-line front-end. The library never writes to the terminal: diagnostics go through the `log` crate, and downloads, extraction and initramfs creation report progress through a caller-supplied `Progress` sink (pass `&NoProgress` for silence, or implement the trait to render your own UI). Rust consumers can use the library directly — resolve an image, download it through the content cache, and run commands with a fully caller-controlled environment, bind targets and architecture:
```toml
[dependencies]
@@ -26,11 +26,11 @@ ecr = { git = "https://github.com/…" } # or a path / registry source
```
```rust
use ecr::{chroot, BindTarget, ExecOptions, PrepareRequest, RootfsCache};
use ecr::{chroot, BindTarget, ExecOptions, NoProgress, PrepareRequest, RootfsCache};
// Download alpine through the cache (~/.cache/ecr) and extract to a scratch dir
let cache = RootfsCache::new(RootfsCache::default_dir()?);
let rootfs = cache.prepare(&PrepareRequest::new("alpine:3.23"))?;
let rootfs = cache.prepare(&PrepareRequest::new("alpine:3.23"), &NoProgress)?;
// Caller-composed envp, explicit bind targets, target architecture
let code = rootfs.exec(&ExecOptions {
@@ -53,7 +53,7 @@ rootfs.persist()?; // write the rootfs back into the cache (see below)
Prepare once, provision once, amortize every later run — including runs from other processes sharing the same cache directory:
```rust
let rootfs = cache.prepare_provisioned(&PrepareRequest::new("alpine:3.23"), |rootfs| {
let rootfs = cache.prepare_provisioned(&PrepareRequest::new("alpine:3.23"), &NoProgress, |rootfs| {
// runs at most once per cache entry
rootfs.exec(&ExecOptions {
command: vec!["apk".into(), "add".into(), "curl".into()],