pub mod cli;
pub mod commands;
pub mod config;
pub mod tui;
use crate::tui::log_err;
pub mod util;
use cli::{CliError, RezonCLI};
use colorful::{Color, Colorful};
use config::rezon_config::RezonConfig;
use tokio;

#[tokio::main]
async fn main() {
	// Run the inner function and handle any errors it produces.
	if let Err(err) = run().await {
		log_err(err.exit_code, err.error.unwrap_or_default().color(Color::Red).bold());
	}
}

async fn run() -> Result<(), CliError<'static>> {
	let args = RezonCLI::parse().get_matches();

	let config = match args.subcommand_name() {
		Some("help") | Some("init") => None,
		_ => Some(RezonConfig::find()?),
	};

	// Errors from the run function will be propagated up to the main function
	RezonCLI::new(config).run(args).await?;

	Ok(())
}
