#![forbid(unsafe_code)]
use std::path::PathBuf;
pub use vanta_core::Platform;
pub fn detect() -> Platform {
Platform::current()
}
pub fn home_dir() -> Option<PathBuf> {
std::env::var_os("HOME")
.or_else(|| std::env::var_os("USERPROFILE"))
.map(PathBuf::from)
}
pub fn vanta_home() -> Option<PathBuf> {
if let Some(h) = std::env::var_os("VANTA_HOME") {
return Some(PathBuf::from(h));
}
home_dir().map(|h| h.join(".vanta"))
}
pub fn path_list_sep() -> char {
if cfg!(windows) {
';'
} else {
':'
}
}
pub fn exe_suffix() -> &'static str {
if cfg!(windows) {
".exe"
} else {
""
}
}
pub fn with_exe(name: &str) -> String {
let suffix = exe_suffix();
if suffix.is_empty() || name.ends_with(suffix) {
name.to_string()
} else {
format!("{name}{suffix}")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn exe_helpers_are_consistent() {
let n = with_exe("node");
if cfg!(windows) {
assert_eq!(n, "node.exe");
assert_eq!(with_exe("node.exe"), "node.exe"); } else {
assert_eq!(n, "node");
}
}
#[test]
fn detect_returns_a_platform() {
assert!(detect().token().contains('/'));
}
}