docs: document the library/CLI output split
The library is terminal-silent: diagnostics through the log facade, progress through Progress sinks. The CLI owns all rendering.
This commit is contained in:
@@ -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()],
|
||||
|
||||
Reference in New Issue
Block a user