use core::error::Error;
use clap::Parser;
use dwd::{cfg::Config, cmd::Cmd, engine::Runtime};
use jemallocator::Jemalloc;
use tokio::runtime::Builder;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
pub fn main() {
let cmd = Cmd::parse();
dwd::logging::init(cmd.verbose as usize).unwrap();
if let Err(err) = run(cmd) {
log::error!("ERROR: {err}");
std::process::exit(1);
}
}
fn run(cmd: Cmd) -> Result<(), Box<dyn Error>> {
let cfg: Config = cmd.try_into()?;
Builder::new_current_thread()
.enable_io()
.enable_time()
.thread_name("runtime")
.build()?
.block_on(async {
let runtime = Runtime::new(cfg);
runtime.run().await
})
}