mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 13:10:24 +01:00
👌 Detect binary paths (#144)
This change introduces binary detection to the app. PHP Monitor does not rely on the user's PATH because the output of a user's terminal can cause issues, so we will scan the two common locations for the Composer binary file. The text in the alert has been modified to accommodate the change (you could still not have Composer installed).
This commit is contained in:
@@ -15,14 +15,18 @@ public class Paths {
|
||||
|
||||
public static let shared = Paths()
|
||||
|
||||
internal var baseDir : Paths.HomebrewDir
|
||||
internal var baseDir: Paths.HomebrewDir
|
||||
|
||||
private var userName : String
|
||||
private var userName: String
|
||||
|
||||
init() {
|
||||
baseDir = App.architecture != "x86_64" ? .opt : .usr
|
||||
userName = String(Shell.pipe("whoami").split(separator: "\n")[0])
|
||||
}
|
||||
|
||||
public func detectBinaryPaths() {
|
||||
detectComposerBinary()
|
||||
}
|
||||
|
||||
// - MARK: Binaries
|
||||
|
||||
@@ -42,6 +46,11 @@ public class Paths {
|
||||
return "\(binPath)/php-config"
|
||||
}
|
||||
|
||||
// - MARK: Detected Binaries
|
||||
|
||||
/** The path to the Composer binary. Can be in multiple locations, so is detected instead. */
|
||||
public static var composer: String? = nil
|
||||
|
||||
// - MARK: Paths
|
||||
|
||||
public static var whoami: String {
|
||||
@@ -64,6 +73,21 @@ public class Paths {
|
||||
return "\(shared.baseDir.rawValue)/etc"
|
||||
}
|
||||
|
||||
// MARK: - Flexible Binaries
|
||||
// (these can be in multiple locations, so we scan common places because)
|
||||
// (PHP Monitor will not use the user's own PATH)
|
||||
|
||||
private func detectComposerBinary() {
|
||||
if Filesystem.fileExists("/usr/local/bin/composer") {
|
||||
Paths.composer = "/usr/local/bin/composer"
|
||||
} else if Filesystem.fileExists("/opt/homebrew/bin/composer") {
|
||||
Paths.composer = "/opt/homebrew/bin/composer"
|
||||
} else {
|
||||
Paths.composer = nil
|
||||
Log.warn("Composer was not found.")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Enum
|
||||
|
||||
public enum HomebrewDir: String {
|
||||
|
||||
Reference in New Issue
Block a user