Skip to main content

detect_here

Function detect_here 

Source
pub fn detect_here() -> Backend
Expand description

detect for this process: its platform, and the path it would run the tool from — PATH, and the sbin directories a service manager’s path has and a login shell’s often lacks, because ufw and nft live there.

use majordomus_cli::mesh::firewall::{detect, detect_here, Backend};

let here = detect_here();
// the same decision `detect` makes for this platform with a real path lookup
let looked_up = detect(std::env::consts::OS, &|name| {
    std::env::var_os("PATH").map_or(false, |p| {
        std::env::split_paths(&p)
            .chain(["/usr/sbin", "/sbin", "/usr/local/sbin"].map(std::path::PathBuf::from))
            .any(|d| d.join(name).is_file())
    })
});
assert_eq!(here, looked_up);