use super::app::AppContext;
use super::commands::{Cli, Commands};
use super::error::CliResult;
#[cfg(feature = "docker")]
use super::handle_docker;
#[cfg(feature = "kubernetes")]
use super::handle_kubernetes;
#[cfg(feature = "monitoring")]
use super::handle_monitoring;
#[cfg(feature = "nordvpn")]
use super::handle_nordvpn;
#[cfg(feature = "secrets")]
use super::handle_secrets;
use super::{
handle_api, handle_config, handle_curl, handle_diag, handle_done, handle_env, handle_flush,
handle_generate, handle_init, handle_install, handle_list, handle_login, handle_logs,
handle_logs_flag, handle_monitor, handle_nginx, handle_no_command, handle_ports,
handle_redeploy, handle_redeploy_v2, handle_resurrect, handle_service, handle_services,
handle_setup, handle_snapshot, handle_start, handle_stop, handle_tail, handle_version,
};
pub async fn dispatch(cli: Cli, ctx: &mut AppContext) -> CliResult<()> {
let debug = ctx.debug();
if cli.logs {
return handle_logs_flag().await;
}
if cli.list && cli.command.is_none() {
handle_list(debug).await?;
return Ok(());
}
match cli.command {
Some(Commands::Ports(cmd)) => handle_ports(cmd, cli.port, debug).await,
Some(Commands::Init) => handle_init(debug).await,
Some(Commands::Setup) => handle_setup(debug).await,
Some(Commands::Redeploy { service_name }) => handle_redeploy(service_name, debug).await,
Some(Commands::RedeployV2(cmd)) => handle_redeploy_v2(cmd, debug).await,
Some(Commands::Config(cmd)) => handle_config(cmd, debug).await,
Some(Commands::Install { package }) => handle_install(package, debug).await,
Some(Commands::Logs(cmd)) => handle_logs(cmd, debug).await,
Some(Commands::List) => handle_list(debug).await,
Some(Commands::Curl(cmd)) => handle_curl(cmd, debug).await,
Some(Commands::Services) => handle_services(debug).await,
Some(Commands::Service {
command,
service_name,
}) => handle_service(command, service_name, debug).await,
Some(Commands::Nginx(cmd)) => handle_nginx(cmd.command, debug).await,
Some(Commands::Diag(cmd)) => handle_diag(cmd, debug).await,
Some(Commands::Monitor(cmd)) => handle_monitor(cmd, debug).await,
Some(Commands::Snapshot) => handle_snapshot(debug).await,
Some(Commands::Resurrect) => handle_resurrect(debug).await,
Some(Commands::Stop { target }) => handle_stop(target, debug).await,
Some(Commands::Flush { target }) => handle_flush(target, debug).await,
Some(Commands::Login) => handle_login().await,
Some(Commands::Version(cmd)) => handle_version(cmd, debug).await,
Some(Commands::Env { target }) => handle_env(target, debug).await,
Some(Commands::Tail(cmd)) => handle_tail(cmd, debug).await,
Some(Commands::Start { args }) => handle_start(args, debug).await,
Some(Commands::Generate(cmd)) => handle_generate(cmd, debug).await,
Some(Commands::Api(cmd)) => handle_api(cmd, debug).await,
#[cfg(feature = "docker")]
Some(Commands::Docker(cmd)) => handle_docker(cmd, debug).await,
#[cfg(feature = "secrets")]
Some(Commands::Secrets(cmd)) => handle_secrets(cmd, debug).await,
Some(Commands::Done(cmd)) => handle_done(cmd, debug).await,
#[cfg(feature = "kubernetes")]
Some(Commands::Kubernetes(cmd)) => handle_kubernetes(cmd, debug).await,
#[cfg(feature = "nordvpn")]
Some(Commands::Nordvpn(cmd)) => handle_nordvpn(cmd, debug).await,
#[cfg(feature = "monitoring")]
Some(Commands::Monitoring(cmd)) => handle_monitoring(cmd).await,
None => {
handle_no_command(cli.port, debug).await
}
}
}