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