use clap::Parser;

mod cli;
mod core;
mod tui;

use cli::args::Cli;

fn main() -> std::process::ExitCode {
    let cli = Cli::parse();

    let use_tui = cli.command.is_none() || cli.tui;

    let result = if use_tui {
        tui::run_tui()
    } else {
        cli::commands::run(cli)
    };

    match result {
        Ok(()) => std::process::ExitCode::SUCCESS,
        Err(e) => {
            eprintln!("Error: {}", e);
            match e {
                core::ClosureError::AuthRequired => std::process::ExitCode::from(2),
                _ => std::process::ExitCode::FAILURE,
            }
        }
    }
}
