isothrum_machine/install/
brew.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum Trouble {
7 Locked,
10 Outdated,
12 XcodeTooOld,
14}
15
16impl Trouble {
17 #[must_use]
19 pub fn of_line(line: &str) -> Option<Trouble> {
20 if (line.contains("homebrew/locks") && line.contains("Permission denied")) || (line.contains("brew update") && line.contains("already running")) {
21 Some(Trouble::Locked)
22 } else if line.contains("unknown or unsupported macOS version") {
23 Some(Trouble::Outdated)
24 } else if line.contains("is too outdated") || line.contains("Please update to Xcode") {
25 Some(Trouble::XcodeTooOld)
26 } else {
27 None
28 }
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn homebrews_lines_are_read_as_it_prints_them() {
38 assert_eq!(
39 Trouble::of_line("Error: Another `brew update` process is already running."),
40 Some(Trouble::Locked)
41 );
42 assert_eq!(Trouble::of_line("Error: unknown or unsupported macOS version: :dunno"), Some(Trouble::Outdated));
43 assert_eq!(
44 Trouble::of_line("Error: Your Xcode (26.6) at /Applications/Xcode.app is too outdated."),
45 Some(Trouble::XcodeTooOld)
46 );
47 assert_eq!(Trouble::of_line("==> Fetching qemu"), None);
48 }
49}