-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👌 Major changes to PHP version detection
* The information extracted from Homebrew's JSON command now also includes information about linked keg and installations. * The mapped versions in the App class now contain information about the Homebrew installation as well. * A HomebrewDiagnostics class has been added, which is currently able to detect conflicts between the `php` formulae of core and the `shivammathur/php` tap (which is currently an issue, see #54) * Alerts are now displayed as critical if they are truly problematic. * PhpInstallation was renamed to ActivePhpInstallation, to make room for a generic PhpInstallation object which contains cached info. * Shell.pipe() now returns the contents of standardError if standardOutput was empty and there was some data in standardError. This makes it easier to debug the output of commands that output to standardError. (For example, failed brew commands might.)
- Loading branch information
1 parent
52606aa
commit 493b594
Showing
14 changed files
with
339 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// AliasConflict.swift | ||
// PHP Monitor | ||
// | ||
// Created by Nico Verbruggen on 28/11/2021. | ||
// Copyright © 2021 Nico Verbruggen. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class HomebrewDiagnostics { | ||
|
||
enum Errors: String { | ||
case aliasConflict = "alias_conflict" | ||
case installationMismatch = "installation_mismatch" | ||
} | ||
|
||
static let shared = HomebrewDiagnostics() | ||
var errors: [HomebrewDiagnostics.Errors] = [] | ||
|
||
init() { | ||
if self.determineAliasConflicts() { | ||
self.errors.append(.aliasConflict) | ||
} | ||
} | ||
|
||
/** | ||
It is possible to have the `shivammathur/php` tap installed, and for the core homebrew information to be outdated. | ||
This will then result in two different aliases claiming to point to the same formula (`php`). | ||
This will break all linking functionality in PHP Monitor, and the user needs to be informed of this. | ||
|
||
This check only needs to be performed if the `shivammathur/php` tap is active. | ||
*/ | ||
public func determineAliasConflicts() -> Bool | ||
{ | ||
let tapAlias = Shell.pipe("\(Paths.brew) info shivammathur/php/php --json") | ||
|
||
if tapAlias.contains("brew tap shivammathur/php") || tapAlias.contains("Error") { | ||
print("The user does not appear to have tapped: shivammathur/php") | ||
return false | ||
} else { | ||
print("The user DOES have the following tapped: shivammathur/php") | ||
print("Checking for `php` formula conflicts...") | ||
|
||
let tapPhp = try! JSONDecoder().decode( | ||
[HomebrewPackage].self, | ||
from: tapAlias.data(using: .utf8)! | ||
).first! | ||
|
||
if tapPhp.version != App.shared.brewPhpVersion { | ||
print("The `php` formula alias seems to be the different between the tap and core. This could be a problem!") | ||
print("Determining whether both of these versions are installed...") | ||
|
||
let bothInstalled = App.shared.availablePhpVersions.contains(tapPhp.version) | ||
&& App.shared.availablePhpVersions.contains(App.shared.brewPhpVersion) | ||
|
||
if bothInstalled { | ||
print("Both conflicting aliases seem to be installed, warning the user!") | ||
} else { | ||
print("Conflicting aliases are not both installed, seems fine!") | ||
} | ||
|
||
return bothInstalled | ||
} | ||
|
||
print("All seems to be OK. No conflicts.") | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.