1#![forbid(unsafe_code)]
5
6use std::path::PathBuf;
7pub use vanta_core::Platform;
8
9pub fn detect() -> Platform {
11 Platform::current()
12}
13
14pub fn home_dir() -> Option<PathBuf> {
16 std::env::var_os("HOME")
17 .or_else(|| std::env::var_os("USERPROFILE"))
18 .map(PathBuf::from)
19}
20
21pub fn vanta_home() -> Option<PathBuf> {
23 if let Some(h) = std::env::var_os("VANTA_HOME") {
24 return Some(PathBuf::from(h));
25 }
26 home_dir().map(|h| h.join(".vanta"))
27}
28
29pub fn path_list_sep() -> char {
31 if cfg!(windows) {
32 ';'
33 } else {
34 ':'
35 }
36}
37
38pub fn exe_suffix() -> &'static str {
40 if cfg!(windows) {
41 ".exe"
42 } else {
43 ""
44 }
45}
46
47pub fn with_exe(name: &str) -> String {
49 let suffix = exe_suffix();
50 if suffix.is_empty() || name.ends_with(suffix) {
51 name.to_string()
52 } else {
53 format!("{name}{suffix}")
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn exe_helpers_are_consistent() {
63 let n = with_exe("node");
64 if cfg!(windows) {
65 assert_eq!(n, "node.exe");
66 assert_eq!(with_exe("node.exe"), "node.exe"); } else {
68 assert_eq!(n, "node");
69 }
70 }
71
72 #[test]
73 fn detect_returns_a_platform() {
74 assert!(detect().token().contains('/'));
75 }
76}