fix(distro): handle single-quoted IDs, add mint, run cargo fmt

- parse_id now strips both double and single quotes per os-release spec
- distro_family debian arm includes "mint" (legacy Linux Mint ID)
- Add tests: single-quoted ID round-trip, mint family classification
This commit is contained in:
pyr0ball 2026-05-18 16:55:06 -07:00
parent dc45c82aba
commit a94e3dbb66

View file

@ -7,9 +7,7 @@ pub fn detect() -> String {
pub fn distro_family(id: &str) -> &'static str { pub fn distro_family(id: &str) -> &'static str {
match id { match id {
"arch" | "cachyos" | "endeavouros" | "manjaro" | "garuda" => "arch", "arch" | "cachyos" | "endeavouros" | "manjaro" | "garuda" => "arch",
"debian" | "ubuntu" | "linuxmint" | "pop" | "elementary" | "kali" => { "debian" | "ubuntu" | "linuxmint" | "mint" | "pop" | "elementary" | "kali" => "debian",
"debian"
}
"fedora" | "rhel" | "centos" | "rocky" | "alma" => "fedora", "fedora" | "rhel" | "centos" | "rocky" | "alma" => "fedora",
"opensuse" | "opensuse-tumbleweed" | "opensuse-leap" => "opensuse", "opensuse" | "opensuse-tumbleweed" | "opensuse-leap" => "opensuse",
_ => "unknown", _ => "unknown",
@ -22,7 +20,13 @@ fn parse_id(content: &str) -> String {
.find_map(|line| { .find_map(|line| {
let (key, val) = line.split_once('=')?; let (key, val) = line.split_once('=')?;
if key.trim() == "ID" { if key.trim() == "ID" {
Some(val.trim().trim_matches('"').to_lowercase()) let raw = val.trim();
let unquoted = raw
.strip_prefix('"')
.and_then(|s| s.strip_suffix('"'))
.or_else(|| raw.strip_prefix('\'').and_then(|s| s.strip_suffix('\'')))
.unwrap_or(raw);
Some(unquoted.to_lowercase())
} else { } else {
None None
} }
@ -70,4 +74,15 @@ mod tests {
fn distro_family_unknown() { fn distro_family_unknown() {
assert_eq!(distro_family("slackware"), "unknown"); assert_eq!(distro_family("slackware"), "unknown");
} }
#[test]
fn parses_single_quoted_id() {
let content = "ID='arch'\nPRETTY_NAME='Arch Linux'\n";
assert_eq!(parse_id(content), "arch");
}
#[test]
fn distro_family_mint_legacy() {
assert_eq!(distro_family("mint"), "debian");
}
} }