executesoft 0.1.1

ExecuteSoft repository automation CLI
use crate::cli::{Cli, Commands, DeployCommand};
use crate::db::run_db_command;
use crate::dev::run_dev_command;
use crate::gateway::run_gateway_command;
use crate::service::run_service_command;
use crate::util::{Result, make_vars, repo_root, run_cmd, run_make};

pub(crate) fn run_cli(cli: Cli) -> Result<()> {
    match cli.command {
        Commands::Service { command } => run_service_command(command),
        Commands::Gateway { command } => run_gateway_command(command),
        Commands::Db { command } => run_db_command(command),
        Commands::Dev { command } => run_dev_command(command),
        Commands::Sync => run_sync(),
        Commands::Release(args) => run_release(&args.vars),
        Commands::Deploy { command } => run_deploy_command(command),
    }
}

fn run_deploy_command(command: DeployCommand) -> Result<()> {
    match command {
        DeployCommand::Kubernetes(args) => {
            run_sync()?;
            run_make(
                &repo_root().join("devops"),
                "deploy-kubernetes",
                &make_vars(&args.vars),
            )
        }
        DeployCommand::Docker(args) => run_make(
            &repo_root().join("devops"),
            "deploy-docker",
            &make_vars(&args.vars),
        ),
    }
}

fn run_sync() -> Result<()> {
    run_cmd(
        &repo_root(),
        "devops/droplet/scripts/sync-service-assets.sh",
        &[],
    )
}

fn run_release(args: &[String]) -> Result<()> {
    run_make(&repo_root().join("devops"), "release", &make_vars(args))
}