Skip to main content

systemprompt_models/config/
environment.rs

1//! Environment detection and configuration.
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum Environment {
5    Development,
6    Production,
7    Test,
8}
9
10impl Environment {
11    pub fn detect() -> Self {
12        if let Ok(env) = std::env::var("SYSTEMPROMPT_ENV") {
13            return Self::from_string(&env);
14        }
15
16        if let Ok(env) = std::env::var("RAILWAY_ENVIRONMENT") {
17            if env == "production" {
18                return Self::Production;
19            }
20        }
21
22        if let Ok(env) = std::env::var("NODE_ENV") {
23            return Self::from_string(&env);
24        }
25
26        if std::env::var("DOCKER_CONTAINER").is_ok() {
27            return Self::Production;
28        }
29
30        if cfg!(debug_assertions) {
31            return Self::Development;
32        }
33
34        Self::Production
35    }
36
37    fn from_string(s: &str) -> Self {
38        match s.to_lowercase().as_str() {
39            "development" | "dev" => Self::Development,
40            "test" | "testing" => Self::Test,
41            _ => Self::Production,
42        }
43    }
44
45    pub const fn is_development(&self) -> bool {
46        matches!(self, Self::Development)
47    }
48
49    pub const fn is_production(&self) -> bool {
50        matches!(self, Self::Production)
51    }
52
53    pub const fn is_test(&self) -> bool {
54        matches!(self, Self::Test)
55    }
56}
57
58impl Default for Environment {
59    fn default() -> Self {
60        Self::detect()
61    }
62}