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