1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-09 12:43:01 +02:00

🏗 WIP: Use BrewFormula struct for operations

This commit is contained in:
2023-04-28 14:42:51 +02:00
parent 18496de104
commit 050c154894
4 changed files with 20 additions and 13 deletions

View File

@@ -8,7 +8,7 @@
import Foundation import Foundation
class BrewFormula { struct BrewFormula {
/// Name of the formula. /// Name of the formula.
let name: String let name: String
@@ -31,11 +31,16 @@ class BrewFormula {
return upgradeVersion != nil return upgradeVersion != nil
} }
public func getHomebrewFolder() -> String { var homebrewFolder: String {
#error("This must return the path to the Homebrew folder") let resolved = name
.replacingOccurrences(of: "shivammathur/php/", with: "")
.replacingOccurrences(of: "php@" + PhpEnv.brewPhpAlias, with: "php")
return "\(Paths.optPath)/\(resolved)/bin"
} }
public func isHealthy() -> Bool { public func isHealthy() -> Bool {
#error("This must check if the PHP version works") return true
// #error("This must check if the PHP version works")
} }
} }

View File

@@ -10,8 +10,8 @@ import Foundation
class HomebrewOperation { class HomebrewOperation {
let installing: [String] let installing: [BrewFormula]
let upgrading: [String] let upgrading: [BrewFormula]
/** /**
You can pass in which PHP versions need to be upgraded and which ones need to be installed. You can pass in which PHP versions need to be upgraded and which ones need to be installed.
@@ -20,8 +20,8 @@ class HomebrewOperation {
Each version that is installed will need to be checked afterwards (if it is OK). Each version that is installed will need to be checked afterwards (if it is OK).
*/ */
public init( public init(
upgrading: [String], upgrading: [BrewFormula],
installing: [String] installing: [BrewFormula]
) { ) {
self.installing = installing self.installing = installing
self.upgrading = upgrading self.upgrading = upgrading
@@ -36,7 +36,7 @@ class HomebrewOperation {
let command = """ let command = """
export HOMEBREW_NO_INSTALL_UPGRADE=true; \ export HOMEBREW_NO_INSTALL_UPGRADE=true; \
export HOMEBREW_NO_INSTALL_CLEANUP=true; \ export HOMEBREW_NO_INSTALL_CLEANUP=true; \
\(Paths.brew) upgrade \(self.upgrading.joined(separator: " ")) \(Paths.brew) upgrade \(self.upgrading.map { $0.name }.joined(separator: " "))
""" """
print(command) print(command)
@@ -46,13 +46,13 @@ class HomebrewOperation {
let command = """ let command = """
export HOMEBREW_NO_INSTALL_UPGRADE=true; \ export HOMEBREW_NO_INSTALL_UPGRADE=true; \
export HOMEBREW_NO_INSTALL_CLEANUP=true; \ export HOMEBREW_NO_INSTALL_CLEANUP=true; \
\(Paths.brew) install \(self.upgrading.joined(separator: " ")) --force \(Paths.brew) install \(self.upgrading.map { $0.name }.joined(separator: " ")) --force
""" """
print(command) print(command)
} }
private func determineHealth(formula: String) -> Bool { private func determineHealth(formula: BrewFormula) -> Bool {
#warning("Should return proper health") #warning("Should return proper health")
return false return false

View File

@@ -124,6 +124,7 @@ struct PhpFormulaeView: View {
.padding(.horizontal, 5) .padding(.horizontal, 5)
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(formula.displayName).bold() Text(formula.displayName).bold()
Text(formula.homebrewFolder)
if formula.isInstalled && formula.hasUpgrade { if formula.isInstalled && formula.hasUpgrade {
Text("\(formula.installedVersion!) installed, \(formula.upgradeVersion!) available.") Text("\(formula.installedVersion!) installed, \(formula.upgradeVersion!) available.")
@@ -139,6 +140,8 @@ struct PhpFormulaeView: View {
} }
} }
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
/*
if formula.isInstalled { if formula.isInstalled {
Button("phpman.buttons.uninstall".localizedForSwiftUI, role: .destructive) { Button("phpman.buttons.uninstall".localizedForSwiftUI, role: .destructive) {
Task { await self.confirmUninstall(formula) } Task { await self.confirmUninstall(formula) }
@@ -148,7 +151,6 @@ struct PhpFormulaeView: View {
Task { await self.install(formula) } Task { await self.install(formula) }
} }
} }
/*
if formula.hasUpgrade { if formula.hasUpgrade {
Button("phpman.buttons.update".localizedForSwiftUI) { Button("phpman.buttons.update".localizedForSwiftUI) {
Task { await self.install(formula, upgrade: true) } Task { await self.install(formula, upgrade: true) }

View File

@@ -101,7 +101,7 @@
"phpman.title" = "PHP Version Manager"; "phpman.title" = "PHP Version Manager";
"phpman.description" = "**PHP Version Manager** lets you install different PHP versions via Homebrew."; "phpman.description" = "**PHP Version Manager** lets you install different PHP versions via Homebrew.";
"phpman.disclaimer" = "Please note that installing or upgrading PHP versions may cause other Homebrew packages to be upgraded as well. If you haven't updated Homebrew in a bit, operations here may take a couple of minutes to complete as it is likely multiple dependencies and other (unrelated) packages will also be upgraded. (Partial upgrades aren't done to avoid breaking packages in general.)"; "phpman.disclaimer" = "Please note that installing or upgrading PHP versions may cause other Homebrew packages to be upgraded as well. Installing or updating PHP versions may take some time, so please be patient.";
"phpman.refresh.button" = "Search for Updates"; "phpman.refresh.button" = "Search for Updates";
"phpman.refresh.button.description" = "You can press the refresh button to check if any updates are available to installed PHP versions."; "phpman.refresh.button.description" = "You can press the refresh button to check if any updates are available to installed PHP versions.";