use std::collections::HashMap;
#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum DevEnvironment {
#[default]
Dev,
Staging,
Production,
Custom(String),
}
#[allow(dead_code)] impl DevEnvironment {
pub fn parse_environment(s: &str) -> Self {
match s.to_lowercase().as_str() {
"dev" | "development" => Self::Dev,
"staging" | "stage" => Self::Staging,
"production" | "prod" => Self::Production,
_ => Self::Custom(s.to_string()),
}
}
pub fn as_str(&self) -> &str {
match self {
Self::Dev => "dev",
Self::Staging => "staging",
Self::Production => "production",
Self::Custom(s) => s.as_str(),
}
}
pub fn display_name(&self) -> String {
match self {
Self::Dev => "Development".to_string(),
Self::Staging => "Staging".to_string(),
Self::Production => "Production".to_string(),
Self::Custom(s) => s.clone(),
}
}
}
#[allow(dead_code)] #[derive(Debug, Clone)]
pub struct DevConfig {
pub environment: DevEnvironment,
pub watch: bool,
pub no_build: bool,
pub nodes: Vec<String>,
pub auto_start_services: bool,
pub flush_redis: bool,
pub env_vars: HashMap<String, String>,
}
#[allow(dead_code)] impl DevConfig {
pub fn new(environment: DevEnvironment) -> Self {
Self {
environment,
watch: false,
no_build: false,
nodes: Vec::new(),
auto_start_services: true,
flush_redis: true,
env_vars: HashMap::new(),
}
}
pub fn with_watch(mut self, enabled: bool) -> Self {
self.watch = enabled;
self
}
pub fn with_no_build(mut self, enabled: bool) -> Self {
self.no_build = enabled;
self
}
pub fn with_nodes(mut self, nodes: Vec<String>) -> Self {
self.nodes = nodes;
self
}
pub fn with_node(mut self, node: impl Into<String>) -> Self {
self.nodes.push(node.into());
self
}
pub fn with_auto_start_services(mut self, enabled: bool) -> Self {
self.auto_start_services = enabled;
self
}
pub fn with_flush_redis(mut self, enabled: bool) -> Self {
self.flush_redis = enabled;
self
}
pub fn with_env_var(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.env_vars.insert(key.into(), value.into());
self
}
pub fn with_env_vars(mut self, vars: HashMap<String, String>) -> Self {
self.env_vars.extend(vars);
self
}
}
impl Default for DevConfig {
fn default() -> Self {
Self::new(DevEnvironment::default())
}
}