/* Written By Angel Uniminin <uniminin@zoho.com> under the terms of MIT */

use std::{env, process};

use colored::Colorize;
use nanogrep::Config;

const ERR_INIT: &str = "Fatal:";

fn main() {
    /* `unwrap_or_else` for non-panic error handling. Using an anonymous function. */
    let config: Config = Config::new(env::args()).unwrap_or_else(|err: &str| {
        /* printing the error to the standard error instead of standard output */
        eprintln!("{:1} {:1}", ERR_INIT.red(), err.to_string().red());
        process::exit(0x01);
    });

    /* `if let` is used to check if an `Err` type is actually returned. */
    if let Err(err) = nanogrep::run(config) {
        eprintln!("{:1} {:1}", ERR_INIT.red(), err.to_string().red());
        process::exit(0x01); /* To exit neatly without any other info spewed out */
    }
}
