Skip to main content

smbcloud_network/
environment.rs

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