Skip to content

Commit 856e480

Browse files
committed
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 <[email protected]>
1 parent b06d75f commit 856e480

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

Cargo.lock

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ inherits = "release"
4343
lto = "yes"
4444

4545
[workspace.dependencies]
46+
anstream = "0.6"
4647
anyhow = "1.0.82"
4748
camino = "1.1.6"
4849
cap-std-ext = "4.0.3"
@@ -55,6 +56,7 @@ indicatif = "0.17.0"
5556
fn-error-context = "0.2.1"
5657
libc = "0.2.154"
5758
openssl = "0.10.72"
59+
owo-colors = { version = "4" }
5860
rustix = { "version" = "1", features = ["thread", "net", "fs", "system", "process", "mount"] }
5961
serde = "1.0.199"
6062
serde_json = "1.0.116"

cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ default-run = "bootc"
1414
platforms = ["*-unknown-linux-gnu"]
1515

1616
[dependencies]
17+
anstream = { workspace = true }
1718
anyhow = { workspace = true }
1819
bootc-lib = { version = "1.0", path = "../lib" }
1920
bootc-utils = { path = "../utils" }
2021
tokio = { workspace = true, features = ["macros"] }
2122
log = "0.4.21"
23+
owo-colors = { workspace = true }
2224
tracing = { workspace = true }
2325

2426
[lints]

cli/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! The main entrypoint for bootc, which just performs global initialization, and then
22
//! calls out into the library.
3+
//!
4+
use std::io::Write as _;
5+
36
use anyhow::Result;
47

58
/// The code called after we've done process global init and created
@@ -32,11 +35,15 @@ fn run() -> Result<()> {
3235
}
3336

3437
fn main() {
38+
use owo_colors::OwoColorize;
39+
3540
// In order to print the error in a custom format (with :#) our
3641
// main simply invokes a run() where all the work is done.
3742
// This code just captures any errors.
3843
if let Err(e) = run() {
39-
tracing::error!("{:#}", e);
44+
let mut stderr = anstream::stderr();
45+
// Don't panic if writing fails
46+
let _ = writeln!(stderr, "{}{:#}", "error: ".red(), e);
4047
std::process::exit(1);
4148
}
4249
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std assert
2+
use tap.nu
3+
4+
tap begin "verify bootc status output formats"
5+
6+
assert equal (bootc switch blah:// e>| find "\u{1B}") []
7+
8+
tap ok

tmt/tests/booted/test-install-outside-container.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mkfs.ext4 disk.img
88
mount -o loop disk.img /var/mnt
99

1010
# attempt to install to filesystem without specifying a source-imgref
11-
let result = bootc install to-filesystem /var/mnt e>| ansi strip
12-
assert equal $result "ERROR Installing to filesystem: Either --source-imgref must be defined or this command must be executed inside a podman container."
11+
let result = bootc install to-filesystem /var/mnt e>| find "--source-imgref must be defined"
12+
assert not equal $result null
1313

1414
tap ok

0 commit comments

Comments
 (0)