Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "
anstream = { workspace = true }
anyhow = { workspace = true }
log = { workspace = true }
owo-colors = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
tracing = { workspace = true }

Expand Down
14 changes: 1 addition & 13 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! 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
Expand Down Expand Up @@ -35,15 +33,5 @@ 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() {
let mut stderr = anstream::stderr();
// Don't panic if writing fails
let _ = writeln!(stderr, "{}{:#}", "error: ".red(), e);
std::process::exit(1);
}
bootc_utils::run_main(run)
}
1 change: 1 addition & 0 deletions crates/system-reinstall-bootc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bootc-mount = { path = "../mount" }
bootc-utils = { package = "bootc-internal-utils", path = "../utils", version = "0.0.0" }

# Workspace dependencies
anstream = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }
indoc = { workspace = true }
Expand Down
8 changes: 1 addition & 7 deletions crates/system-reinstall-bootc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,5 @@ fn run() -> Result<()> {
}

fn main() {
// 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);
std::process::exit(1);
}
bootc_utils::run_main(run)
}
2 changes: 2 additions & 0 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ repository = "https://github.com/bootc-dev/bootc"

[dependencies]
# Workspace dependencies
anstream = { workspace = true }
anyhow = { workspace = true }
chrono = { workspace = true, features = ["std"] }
owo-colors = { workspace = true }
rustix = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
18 changes: 18 additions & 0 deletions crates/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ pub use tracing_util::*;
pub mod reexec;
mod result_ext;
pub use result_ext::*;

/// Intended for use in `main`, calls an inner function and
/// handles errors by printing them.
pub fn run_main<F>(f: F)
where
F: FnOnce() -> anyhow::Result<()>,
{
use std::io::Write as _;

use owo_colors::OwoColorize;

if let Err(e) = f() {
let mut stderr = anstream::stderr();
// Don't panic if writing fails.
let _ = writeln!(stderr, "{}{:#}", "error: ".red(), e);
std::process::exit(1);
}
}