forklaunch 1.15.0

Launch faster with forklaunch
use anyhow::Result;
use clap::{ArgMatches, Command};

use crate::{CliCommand, core::command::command};

mod config_set;
mod delete;
mod lifecycle;
mod list;
mod mutation;
mod resize;
mod resource_resolver;
mod status;
mod stop;
mod types;

use config_set::ConfigSetCommand;
use delete::DeleteCommand;
use list::ListCommand;
use resize::ResizeCommand;
use status::StatusCommand;
use stop::StopCommand;

#[derive(Debug)]
pub(crate) struct InfraCommand {
    list: ListCommand,
    status: StatusCommand,
    resize: ResizeCommand,
    config_set: ConfigSetCommand,
    stop: StopCommand,
    delete: DeleteCommand,
}

impl InfraCommand {
    pub(crate) fn new() -> Self {
        Self {
            list: ListCommand::new(),
            status: StatusCommand::new(),
            resize: ResizeCommand::new(),
            config_set: ConfigSetCommand::new(),
            stop: StopCommand::new(),
            delete: DeleteCommand::new(),
        }
    }
}

impl CliCommand for InfraCommand {
    fn command(&self) -> Command {
        command(
            "infra",
            "Inspect and manage provisioned database, cache, and queue infrastructure",
        )
        .subcommand(self.list.command())
        .subcommand(self.status.command())
        .subcommand(self.resize.command())
        .subcommand(self.config_set.command())
        .subcommand(self.stop.command())
        .subcommand(self.delete.command())
        .subcommand_required(true)
    }

    fn handler(&self, matches: &ArgMatches) -> Result<()> {
        match matches.subcommand() {
            Some(("list", sub_matches)) => self.list.handler(sub_matches),
            Some(("status", sub_matches)) => self.status.handler(sub_matches),
            Some(("resize", sub_matches)) => self.resize.handler(sub_matches),
            Some(("config-set", sub_matches)) => self.config_set.handler(sub_matches),
            Some(("stop", sub_matches)) => self.stop.handler(sub_matches),
            Some(("delete", sub_matches)) => self.delete.handler(sub_matches),
            _ => unreachable!(),
        }
    }
}