cargo-ibuild 1.2.1

cargo-ibuild
mod cargo_toml;
mod config;
mod docker;
mod param;

use config::ARM64_TARGET;
use docker::{build, exec, run};
use param::{get_channel_and_target, get_param};
use std::{env, error::Error};

fn main() -> Result<(), Box<dyn Error>> {
    let mut args: Vec<String> = env::args().collect::<Vec<String>>()[1..].to_vec();
    if args.len() > 0 && args[0] == "ibuild" {
        args = args[1..].to_vec();
    }

    // get active channel and targets
    let (active_channel, active_target) = get_channel_and_target(&mut args)?;

    // ubuntu
    let is_ubuntu = get_param(&mut args, "--ubuntu", false, true);
    if active_target == ARM64_TARGET && is_ubuntu {
        panic!("--ubuntu is not supported for arm64");
    }

    let is_alma = get_param(&mut args, "--alma", false, true);
    if is_alma && is_ubuntu {
        panic!("--alma and --ubuntu cannot be used together");
    }

    if args.len() > 0 && args[0] == "run" {
        // run docker
        run(&active_channel, &active_target, is_ubuntu, is_alma)?;
    } else if args.len() > 0 && args[0] == "exec" {
        // exec docker
        args = args[1..].to_vec();
        if let Some(idx) = args.iter().position(|x| x == "--") {
            args = args[idx + 1..].to_vec();
        }
        exec(&active_channel, &active_target, is_ubuntu, is_alma, &args)?;
    } else {
        // build
        build(
            &active_channel,
            &active_target,
            is_ubuntu,
            is_alma,
            &mut args,
        )?;
    }
    Ok(())
}