use serde::{Deserialize, Serialize};
use tracing::warn;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Platform {
MacOS,
Linux,
Windows,
}
impl Platform {
pub fn detect() -> Self {
match std::env::consts::OS {
"macos" => Platform::MacOS,
"linux" => Platform::Linux,
"windows" => Platform::Windows,
os => {
warn!("Unknown OS '{os}', defaulting to Linux");
Platform::Linux
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_platform_detection() {
let platform = Platform::detect();
#[cfg(target_os = "macos")]
assert_eq!(platform, Platform::MacOS);
#[cfg(target_os = "linux")]
assert_eq!(platform, Platform::Linux);
#[cfg(target_os = "windows")]
assert_eq!(platform, Platform::Windows);
}
}