use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeploymentTarget {
Cloudflare,
GcpCloudRun,
AwsLambda,
}
impl DeploymentTarget {
#[must_use]
pub fn detect(project_dir: &Path) -> Option<Self> {
if project_dir.join("wrangler.toml").exists() {
Some(Self::Cloudflare)
} else if project_dir.join("service.yaml").exists() {
Some(Self::GcpCloudRun)
} else if project_dir.join("template.yaml").exists() {
Some(Self::AwsLambda)
} else {
None
}
}
#[must_use]
pub fn config_file(self) -> &'static str {
match self {
Self::Cloudflare => "wrangler.toml",
Self::GcpCloudRun => "service.yaml",
Self::AwsLambda => "template.yaml",
}
}
#[must_use]
pub fn from_provider_name(name: &str) -> Option<Self> {
match name {
"cloudflare" => Some(Self::Cloudflare),
"gcp" => Some(Self::GcpCloudRun),
"aws" => Some(Self::AwsLambda),
_ => None,
}
}
#[must_use]
pub fn provider_name(self) -> &'static str {
match self {
Self::Cloudflare => "cloudflare",
Self::GcpCloudRun => "gcp",
Self::AwsLambda => "aws",
}
}
}
impl core::fmt::Display for DeploymentTarget {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.provider_name())
}
}