mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 13:10:24 +01:00
♻️ Refactoring, version bump for M1 support (#20)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum HomebrewDirectory: String {
|
||||
enum HomebrewDir: String {
|
||||
case opt = "/opt/homebrew/bin"
|
||||
case usr = "/usr/local/bin"
|
||||
}
|
||||
@@ -16,24 +16,26 @@ enum HomebrewDirectory: String {
|
||||
class Paths {
|
||||
|
||||
static let shared = Paths()
|
||||
var baseDirectory : HomebrewDirectory
|
||||
var baseDir : HomebrewDir
|
||||
|
||||
init() {
|
||||
let optBrewFound = Shell.fileExists("\(HomebrewDirectory.opt.rawValue)/brew")
|
||||
let usrBrewFound = Shell.fileExists("\(HomebrewDirectory.usr.rawValue)/brew")
|
||||
let optBrewFound = Shell.fileExists("\(HomebrewDir.opt.rawValue)/brew")
|
||||
let usrBrewFound = Shell.fileExists("\(HomebrewDir.usr.rawValue)/brew")
|
||||
|
||||
if (optBrewFound) {
|
||||
self.baseDirectory = .opt
|
||||
// This is usually the case with Homebrew installed on Apple Silicon
|
||||
self.baseDir = .opt
|
||||
} else if (usrBrewFound) {
|
||||
self.baseDirectory = .usr
|
||||
// This is usually the case with Homebrew installed on Intel (or Rosetta 2)
|
||||
self.baseDir = .usr
|
||||
} else {
|
||||
// Falling back to Intel
|
||||
print("Seems like we couldn't determine the architecture.")
|
||||
// Falling back to default "legacy" Homebrew location (for Intel)
|
||||
print("Seems like we couldn't determine the Homebrew directory.")
|
||||
print("This usually means we're in trouble... (no Homebrew?)")
|
||||
self.baseDirectory = .usr
|
||||
self.baseDir = .usr
|
||||
}
|
||||
|
||||
print("Homebrew directory: \(self.baseDirectory)")
|
||||
print("Homebrew directory: \(self.baseDir)")
|
||||
}
|
||||
|
||||
public static func brew() -> String {
|
||||
@@ -45,11 +47,11 @@ class Paths {
|
||||
}
|
||||
|
||||
public static func binPath() -> String {
|
||||
return self.shared.baseDirectory.rawValue
|
||||
return self.shared.baseDir.rawValue
|
||||
}
|
||||
|
||||
public static func optPath() -> String {
|
||||
switch self.shared.baseDirectory {
|
||||
switch self.shared.baseDir {
|
||||
case .opt:
|
||||
return "/opt/homebrew/opt"
|
||||
case .usr:
|
||||
@@ -58,7 +60,7 @@ class Paths {
|
||||
}
|
||||
|
||||
public static func etcPath() -> String {
|
||||
switch self.shared.baseDirectory {
|
||||
switch self.shared.baseDir {
|
||||
case .opt:
|
||||
return "/opt/homebrew/etc"
|
||||
case .usr:
|
||||
|
||||
@@ -47,9 +47,12 @@ class Shell {
|
||||
)!
|
||||
}
|
||||
|
||||
public static func fileExists(_ filePath: String) -> Bool {
|
||||
/**
|
||||
Checks if a file exists at the provided path.
|
||||
*/
|
||||
public static func fileExists(_ path: String) -> Bool {
|
||||
return Shell.user.pipe(
|
||||
"if [ -f \(filePath) ]; then echo \"Y\"; fi"
|
||||
).contains("Y")
|
||||
"if [ -f \(path) ]; then echo \"PHP_Y_FE\"; fi"
|
||||
).contains("PHP_Y_FE")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user