#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Trouble {
Locked,
Outdated,
XcodeTooOld,
}
impl Trouble {
#[must_use]
pub fn of_line(line: &str) -> Option<Trouble> {
if (line.contains("homebrew/locks") && line.contains("Permission denied")) || (line.contains("brew update") && line.contains("already running")) {
Some(Trouble::Locked)
} else if line.contains("unknown or unsupported macOS version") {
Some(Trouble::Outdated)
} else if line.contains("is too outdated") || line.contains("Please update to Xcode") {
Some(Trouble::XcodeTooOld)
} else {
None
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn homebrews_lines_are_read_as_it_prints_them() {
assert_eq!(
Trouble::of_line("Error: Another `brew update` process is already running."),
Some(Trouble::Locked)
);
assert_eq!(Trouble::of_line("Error: unknown or unsupported macOS version: :dunno"), Some(Trouble::Outdated));
assert_eq!(
Trouble::of_line("Error: Your Xcode (26.6) at /Applications/Xcode.app is too outdated."),
Some(Trouble::XcodeTooOld)
);
assert_eq!(Trouble::of_line("==> Fetching qemu"), None);
}
}