use std::process::ExitCode;
use std::sync::atomic::{AtomicBool, Ordering};
use clap::Parser;
use hop::cli::output::EXIT_INTERRUPTED;
use hop::cli::{self, Cli};
use hop::util::{logging, paths};
static INTERRUPTED: AtomicBool = AtomicBool::new(false);
fn main() -> ExitCode {
let cli = Cli::parse();
if cli.is_color_disabled() {
disable_color();
}
let _ = logging::init(cli.log_level(), Some(&paths::log_file()));
install_interrupt_handler();
let code = cli::run(cli);
if INTERRUPTED.load(Ordering::SeqCst) {
return ExitCode::from(EXIT_INTERRUPTED);
}
code
}
fn disable_color() {
unsafe { std::env::set_var("NO_COLOR", "1") };
}
fn install_interrupt_handler() {
let _ = ctrlc::set_handler(|| {
INTERRUPTED.store(true, Ordering::SeqCst);
});
}