#[cfg(feature = "jemalloc")]
use tikv_jemallocator::Jemalloc;
#[cfg(feature = "jemalloc")]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
use clap::Parser;
use env_logger::Env;
use maram::{run_tree, Args, Config, Result};
use std::error::Error;
use std::path::Path;
use std::process;
fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init();
if let Err(e) = run() {
log::error!("Error: {}", e);
eprintln!("Error: {}", e);
let mut source = e.source();
while let Some(err) = source {
eprintln!(" Caused by: {}", err);
source = err.source();
}
process::exit(1);
}
}
fn run() -> Result<()> {
let args = Args::parse();
let config = Config::load()?;
let path = Path::new(&args.path);
if !path.exists() {
return Err(maram::Error::IoError(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("Path does not exist: {}", path.display()),
)));
}
if args.verbose {
log::set_max_level(log::LevelFilter::Debug);
}
let start = std::time::Instant::now();
run_tree(path, &args, &config)?;
if args.bench {
let elapsed = start.elapsed();
eprintln!("\nExecution time: {:.3}s", elapsed.as_secs_f64());
}
Ok(())
}