mod args;
mod modules;
mod utils;

use crate::{
    args::Args,
    modules::{challenge::count_time_to_target, systemage::count_system_age},
};

use clap::Parser;
use colored::*;
use cosmoutils::modules::msg::error;
use std::process::exit;

const VERSION: &str = clap::crate_version!();

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args = Args::parse();

    if args.version {
        println!("{} {VERSION}", "Hourglass:".bold().blue());
        exit(0);
    };

    if let Some(naive_date) = args.set {
        count_time_to_target(&naive_date)?;
        exit(0);
    }

    if let Err(e) = count_system_age() {
        error(e.to_string().as_str());
    }

    Ok(())
}
