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:
parent
dc45c82aba
commit
a94e3dbb66
1 changed files with 19 additions and 4 deletions
|
|
@ -7,9 +7,7 @@ pub fn detect() -> String {
|
|||
pub fn distro_family(id: &str) -> &'static str {
|
||||
match id {
|
||||
"arch" | "cachyos" | "endeavouros" | "manjaro" | "garuda" => "arch",
|
||||
"debian" | "ubuntu" | "linuxmint" | "pop" | "elementary" | "kali" => {
|
||||
"debian"
|
||||
}
|
||||
"debian" | "ubuntu" | "linuxmint" | "mint" | "pop" | "elementary" | "kali" => "debian",
|
||||
"fedora" | "rhel" | "centos" | "rocky" | "alma" => "fedora",
|
||||
"opensuse" | "opensuse-tumbleweed" | "opensuse-leap" => "opensuse",
|
||||
_ => "unknown",
|
||||
|
|
@ -22,7 +20,13 @@ fn parse_id(content: &str) -> String {
|
|||
.find_map(|line| {
|
||||
let (key, val) = line.split_once('=')?;
|
||||
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 {
|
||||
None
|
||||
}
|
||||
|
|
@ -70,4 +74,15 @@ mod tests {
|
|||
fn distro_family_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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue