1use std::process::Command;
2
3use anyhow::{Ok, Result};
4
5
6const BREW_BIN_ARM64: &str = "/opt/homebrew/bin/brew";
7const BREW_BIN_X86_64: &str = "/usr/local/bin/brew";
8
9pub fn get_brew_bin() -> Result<String>{
10 let output = Command::new("uname")
11 .arg("-m")
12 .output()?; if let Some(out) = String::from_utf8_lossy(&output.stdout).strip_suffix("\n") {
14 if out == "x86_64" {
15 return Ok(String::from(BREW_BIN_X86_64));
16 }
17 }
18 Ok(String::from(BREW_BIN_ARM64))
19}
20
21
22#[cfg(test)]
23mod tests {
24 use crate::config::BREW_BIN_ARM64;
25
26 use super::get_brew_bin;
27
28 #[test]
29 fn test_get_bin() {
30 if let Ok(cmd) = get_brew_bin() {
31 assert_eq!(cmd, BREW_BIN_ARM64)
32 }
33 }
34}