Skip to main content

teaql_tool_std/
system.rs

1use std::env;
2use std::env::consts;
3
4pub struct SystemTool;
5
6impl SystemTool {
7    pub fn new() -> Self {
8        Self
9    }
10
11    pub fn env(&self, key: &str) -> Option<String> {
12        env::var(key).ok()
13    }
14
15    pub fn env_or(&self, key: &str, default: &str) -> String {
16        env::var(key).unwrap_or_else(|_| default.to_string())
17    }
18
19    pub fn os(&self) -> &'static str {
20        consts::OS
21    }
22    
23    pub fn arch(&self) -> &'static str {
24        consts::ARCH
25    }
26    
27    pub fn current_dir(&self) -> Option<String> {
28        env::current_dir().ok().map(|p| p.to_string_lossy().into_owned())
29    }
30}
31
32impl Default for SystemTool {
33    fn default() -> Self {
34        Self::new()
35    }
36}