1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 15:45:53 +01:00

cli: Don't emit ANSI codes to stderr

It seems the tracing crate is broken in this respect. Digging
through best practices, `anstream` is used by clap and looks sane.
We're basically just following their example.

Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
Colin Walters
2025-05-29 13:20:30 -04:00
parent b06d75fed7
commit 856e480cb7
6 changed files with 36 additions and 9 deletions

View File

@@ -14,11 +14,13 @@ default-run = "bootc"
platforms = ["*-unknown-linux-gnu"]
[dependencies]
anstream = { workspace = true }
anyhow = { workspace = true }
bootc-lib = { version = "1.0", path = "../lib" }
bootc-utils = { path = "../utils" }
tokio = { workspace = true, features = ["macros"] }
log = "0.4.21"
owo-colors = { workspace = true }
tracing = { workspace = true }
[lints]

View File

@@ -1,5 +1,8 @@
//! The main entrypoint for bootc, which just performs global initialization, and then
//! calls out into the library.
//!
use std::io::Write as _;
use anyhow::Result;
/// The code called after we've done process global init and created
@@ -32,11 +35,15 @@ fn run() -> Result<()> {
}
fn main() {
use owo_colors::OwoColorize;
// In order to print the error in a custom format (with :#) our
// main simply invokes a run() where all the work is done.
// This code just captures any errors.
if let Err(e) = run() {
tracing::error!("{:#}", e);
let mut stderr = anstream::stderr();
// Don't panic if writing fails
let _ = writeln!(stderr, "{}{:#}", "error: ".red(), e);
std::process::exit(1);
}
}