bootc_internal_utils/
lib.rs

1//! The inevitable catchall "utils" crate. Generally only add
2//! things here that only depend on the standard library and
3//! "core" crates.
4//!
5mod bwrap;
6pub use bwrap::*;
7mod command;
8pub use command::*;
9mod iterators;
10pub use iterators::*;
11mod path;
12pub use path::*;
13/// Re-execute the current process
14pub mod reexec;
15mod result_ext;
16pub use result_ext::*;
17mod timestamp;
18pub use timestamp::*;
19mod tracing_util;
20pub use tracing_util::*;
21
22/// The name of our binary
23pub const NAME: &str = "bootc";
24
25/// Intended for use in `main`, calls an inner function and
26/// handles errors by printing them.
27pub fn run_main<F>(f: F)
28where
29    F: FnOnce() -> anyhow::Result<()>,
30{
31    use std::io::Write as _;
32
33    use owo_colors::OwoColorize;
34
35    if let Err(e) = f() {
36        let mut stderr = anstream::stderr();
37        // Don't panic if writing fails.
38        let _ = writeln!(stderr, "{}{:#}", "error: ".red(), e);
39        std::process::exit(1);
40    }
41}