pub fn browser_argv(url: &str) -> Vec<String> {
argv_for(std::env::consts::OS, url)
}
fn argv_for(os: &str, url: &str) -> Vec<String> {
match os {
"macos" => vec!["open".into(), url.into()],
"windows" => vec![
"cmd".into(),
"/C".into(),
"start".into(),
"".into(),
url.into(),
],
_ => vec!["xdg-open".into(), url.into()],
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn macos_uses_open() {
assert_eq!(argv_for("macos", "https://x"), vec!["open", "https://x"]);
}
#[test]
fn windows_uses_cmd_start_with_empty_title() {
assert_eq!(
argv_for("windows", "https://x"),
vec!["cmd", "/C", "start", "", "https://x"]
);
}
#[test]
fn other_uses_xdg_open() {
assert_eq!(
argv_for("linux", "https://x"),
vec!["xdg-open", "https://x"]
);
assert_eq!(
argv_for("freebsd", "https://x"),
vec!["xdg-open", "https://x"]
);
}
#[test]
fn public_entry_feeds_compile_time_os() {
let argv = browser_argv("https://x");
assert_eq!(argv.last().map(String::as_str), Some("https://x"));
assert!(!argv.is_empty());
}
}