#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]

use clap::Parser;
use ordinaryd::{Cli, run, setup};
use std::error::Error;

#[cfg(feature = "mimalloc")]
use mimalloc::MiMalloc;

#[cfg(feature = "mimalloc")]
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

#[cfg(feature = "jemalloc")]
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;

#[cfg(feature = "jemalloc")]
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

#[allow(clippy::too_many_lines)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let cli = Cli::parse();

    let logs_dir = setup(&cli)?;
    run(&cli, &logs_dir.into_boxed_path()).await
}
