mod cli;
mod cli_interrupt;
mod cli_load;
mod cli_output;
mod cli_run;
mod cli_verify;

use clap::Parser;

use crate::{
    cli::{Cli, Invocation},
    cli_run::run,
    cli_verify::verify,
};
use hen::error::print_error;

#[tokio::main]
async fn main() {
    let result = match Cli::parse().into_invocation() {
        Invocation::Run(args) => run(args).await,
        Invocation::Verify(args) => verify(args),
    };

    match result {
        Ok(outcome) => {
            if outcome.exit_code != 0 {
                std::process::exit(outcome.exit_code);
            }
        }
        Err(err) => {
            print_error(&err);
            std::process::exit(err.exit_code());
        }
    }
}