#![allow(unexpected_cfgs)]
#![allow(unused_imports)]
#![allow(dead_code)]
use clap::Subcommand;
use color_eyre::Result;
use std::path::PathBuf;
use url::Url;
mod config;
mod estimate;
mod logs;
mod policy;
mod preflight;
mod status;
mod update;
pub use config::CloudProvider;
pub use policy::{CostOptimization, RemoteDeploymentPolicy};
#[derive(Subcommand, Debug)]
pub enum CloudCommands {
#[command(visible_alias = "cfg")]
Configure {
#[arg(value_enum)]
provider: CloudProvider,
#[arg(short, long)]
region: Option<String>,
#[arg(short = 'd', long)]
set_default: bool,
},
#[command(visible_alias = "policy")]
ConfigurePolicy {
#[command(flatten)]
args: policy::PolicyConfigureArgs,
},
#[command(visible_alias = "show")]
ShowPolicy,
#[command(visible_alias = "cost")]
Estimate {
#[arg(short = 'c', long)]
compare: bool,
#[arg(short, long, value_enum)]
provider: Option<CloudProvider>,
#[arg(long, default_value = "4")]
cpu: f32,
#[arg(long, default_value = "16")]
memory: f32,
#[arg(long)]
gpu: Option<u32>,
#[arg(short = 'd', long, default_value = "24h")]
duration: String,
#[arg(short, long)]
spot: bool,
},
#[command(visible_alias = "s")]
Status {
service_id: Option<String>,
#[arg(short, long)]
watch: bool,
},
#[command(visible_alias = "term")]
Terminate {
service_id: Option<String>,
#[arg(long, conflicts_with = "service_id")]
all: bool,
#[arg(short, long)]
yes: bool,
},
#[command(visible_alias = "up")]
Update {
service_id: String,
#[arg(short, long)]
image: String,
#[arg(short = 's', long, default_value = "blue-green")]
strategy: String,
#[arg(short, long)]
env: Vec<String>,
#[arg(long)]
skip_health_check: bool,
},
#[command(visible_alias = "rb")]
Rollback {
service_id: String,
#[arg(short, long)]
version: Option<String>,
#[arg(short, long)]
yes: bool,
},
#[command(visible_alias = "hist")]
History {
service_id: String,
#[arg(short = 'n', long, default_value = "10")]
limit: usize,
},
#[command(visible_alias = "logs")]
Logs {
service_id: String,
#[arg(short, long)]
follow: bool,
#[arg(short, long)]
level: Option<String>,
#[arg(short, long)]
search: Option<String>,
#[arg(long)]
since: Option<String>,
#[arg(short = 'n', long, default_value = "100")]
lines: usize,
},
#[command(visible_alias = "ls")]
List,
#[command(visible_alias = "check")]
Preflight {
#[arg(short, long, value_enum)]
provider: Option<CloudProvider>,
#[arg(long)]
tee_required: bool,
#[arg(long)]
bootstrap_env: bool,
#[arg(long)]
write_env_file: Option<PathBuf>,
},
}
pub async fn execute(command: CloudCommands) -> Result<()> {
match command {
CloudCommands::Configure {
provider,
region,
set_default,
} => config::configure(provider, region, set_default).await,
CloudCommands::ConfigurePolicy { args } => policy::configure_policy(args).await,
CloudCommands::ShowPolicy => policy::show_policy().await,
CloudCommands::Estimate {
compare,
provider,
cpu,
memory,
gpu,
duration,
spot,
} => {
estimate::estimate(estimate::EstimateOptions {
compare,
provider,
cpu,
memory,
gpu,
duration,
spot,
})
.await
}
CloudCommands::Status { service_id, watch } => status::show_status(service_id, watch).await,
CloudCommands::Terminate {
service_id,
all,
yes,
} => status::terminate(service_id, all, yes).await,
CloudCommands::Update {
service_id,
image,
strategy,
env,
skip_health_check,
} => update::update(service_id, image, strategy, env, skip_health_check).await,
CloudCommands::Rollback {
service_id,
version,
yes,
} => update::rollback(service_id, version, yes).await,
CloudCommands::History { service_id, limit } => update::history(service_id, limit).await,
CloudCommands::Logs {
service_id,
follow,
level,
search,
since,
lines,
} => logs::stream_logs(service_id, follow, level, search, since, lines).await,
CloudCommands::List => config::list_providers().await,
CloudCommands::Preflight {
provider,
tee_required,
bootstrap_env,
write_env_file,
} => preflight::run(provider, tee_required, bootstrap_env, write_env_file).await,
}
}