mod netif;
mod netif_mon;

use clap::{App, Arg};

#[allow(unused)]
use jlogger_tracing::{jdebug, jerror, jinfo, jwarn, JloggerBuilder, LevelFilter, LogTimeFormat};
use netif_mon::NetIfMon;

fn main() {
    let rt = tokio::runtime::Builder::new_multi_thread()
        .thread_stack_size(3 * 1024 * 1024)
        .enable_io()
        .enable_time()
        .thread_name("tokio-rnetmon")
        .build()
        .unwrap();

    let main_work = async {
        let matches = App::new("rnetmon")
            .version("0.1")
            .about("Network manager")
            .arg(
                Arg::new("log-file")
                    .short('l')
                    .long("log-file")
                    .value_name("LOG_FILE")
                    .about("Log file"),
            )
            .arg(
                Arg::new("verbose")
                    .short('v')
                    .multiple_occurrences(true)
                    .about("Level of verbosity"),
            )
            .get_matches();

        let max_level = match matches.occurrences_of("verbose") {
            0 => LevelFilter::INFO,
            1 => LevelFilter::DEBUG,
            _ => LevelFilter::TRACE,
        };

        JloggerBuilder::new()
            .max_level(max_level)
            .log_time(LogTimeFormat::TimeNone)
            .build();

        jinfo!(max_level = matches.occurrences_of("verbose"));
        if let Err(e) = NetIfMon::run().await {
            jerror!("Error: {}", e);
        }
    };

    rt.block_on(async { main_work.await });
}
