smbcloud_networking/
environment.rs

1#[derive(clap::ValueEnum, Clone, Copy)]
2pub enum Environment {
3    Dev,
4    Production,
5}
6
7impl std::fmt::Display for Environment {
8    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9        write!(f, "{}", self.to_str())
10    }
11}
12
13impl std::str::FromStr for Environment {
14    type Err = ();
15
16    fn from_str(s: &str) -> Result<Self, Self::Err> {
17        match s.to_lowercase().as_str() {
18            "dev" => Ok(Environment::Dev),
19            "production" => Ok(Environment::Production),
20            _ => Err(()),
21        }
22    }
23}
24
25impl Environment {
26    pub fn to_str(&self) -> &str {
27        match self {
28            Environment::Dev => "dev",
29            Environment::Production => "production",
30        }
31    }
32    pub fn smb_dir(&self) -> String {
33        match self {
34            Environment::Dev => ".smb-dev".to_string(),
35            Environment::Production => ".smb".to_string(),
36        }
37    }
38
39    pub fn api_protocol(&self) -> String {
40        match self {
41            Environment::Dev => "http".to_string(),
42            Environment::Production => "https".to_string(),
43        }
44    }
45    pub fn api_host(&self) -> String {
46        match self {
47            Environment::Dev => "localhost:8088".to_string(),
48            Environment::Production => "api.smbcloud.xyz".to_string(),
49        }
50    }
51}