1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-07 05:10:06 +01:00

👌 Parse upgradable versions

This commit is contained in:
2023-03-18 02:11:57 +01:00
parent 8f1304308d
commit f8b605f749
6 changed files with 79 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
//
// HomebrewPackage.swift
// HomebrewDecodable.swift
// PHP Monitor
//
// Copyright © 2023 Nico Verbruggen. All rights reserved.
@@ -17,7 +17,6 @@ struct HomebrewPackage: Decodable {
return aliases.first!
.replacingOccurrences(of: "php@", with: "")
}
}
struct HomebrewInstalled: Decodable {
@@ -26,3 +25,15 @@ struct HomebrewInstalled: Decodable {
let installed_as_dependency: Bool
let installed_on_request: Bool
}
struct OutdatedFormulae: Decodable {
let formulae: [OutdatedFormula]
}
struct OutdatedFormula: Decodable {
let name: String
let installed_versions: [String]
let current_version: String
let pinned: Bool
let pinned_version: String?
}

View File

@@ -35,15 +35,31 @@ class Brew {
\(Paths.brew) outdated --json --formulae
"""
let raw = await Shell.pipe(command).out
print(raw)
let rawJsonText = await Shell.pipe(command).out
.data(using: .utf8)!
// We can now figure out what updates there are
let installed = PhpEnv.shared.cachedPhpInstallations.map { key, value in
return (key, value.versionNumber.text)
}
// We also know what's installed
let items = PhpEnv.shared.cachedPhpInstallations.keys
print(items)
let phpAlias = PhpEnv.brewPhpAlias
return []
let outdated = try? JSONDecoder().decode(
OutdatedFormulae.self,
from: rawJsonText
).formulae.filter({ formula in
formula.name.starts(with: "php")
})
return installed.map { (version, fullVersion) in
return BrewFormula(
name: version != phpAlias ? "php@\(version)" : "php",
displayName: version,
installedVersion: fullVersion,
upgradeVersion: outdated?.first(where: { formula in
return formula.installed_versions.contains(fullVersion)
})?.current_version
)
}
}
}

View File

@@ -9,14 +9,24 @@
import Foundation
struct BrewFormula {
/// Name of the formula.
let name: String
/// The human readable name for this formula.
let displayName: String
/// The version of the formula that is currently installed.
let installedVersion: String?
/// The upgrade that is currently available, if it exists.
let upgradeVersion: String?
/// Whether the formula is currently installed.
var isInstalled: Bool {
return installedVersion != nil
}
/// Whether the formula can be upgraded.
var hasUpgrade: Bool {
return upgradeVersion != nil
}

View File

@@ -35,7 +35,7 @@ struct PhpInstallable {
}
}
struct ContentView: View {
struct PhpInstallationList: View {
@State var phpVersions: [PhpInstallable]
var body: some View {
@@ -98,16 +98,18 @@ struct ContentView: View {
}
}
struct ContentView_Previews: PreviewProvider {
struct PhpInstallationList_Previews: PreviewProvider {
static var previews: some View {
ContentView(phpVersions: [
PhpInstallable(name: "PHP 8.2", installed: "8.2.3", latest: "8.2.3", actions: []),
PhpInstallable(name: "PHP 8.1", installed: "8.1.0", latest: "8.1.5", actions: [.upgrade, .remove]),
PhpInstallationList(phpVersions: [
PhpInstallable(name: "PHP 8.2", installed: "8.2.3", latest: "8.2.4", actions: [.upgrade]),
PhpInstallable(name: "PHP 8.1", installed: "8.1.15", latest: "8.1.16", actions: [.upgrade, .remove]),
PhpInstallable(name: "PHP 8.0", installed: "8.0.14", latest: "8.0.14", actions: [.remove]),
PhpInstallable(name: "PHP 7.4", installed: nil, latest: "", actions: [.install]),
PhpInstallable(name: "PHP 7.3", installed: nil, latest: "", actions: [.install]),
PhpInstallable(name: "PHP 7.2", installed: nil, latest: "", actions: [.install]),
PhpInstallable(name: "PHP 7.1", installed: nil, latest: "", actions: [.install])
PhpInstallable(name: "PHP 7.1", installed: nil, latest: "", actions: [.install]),
PhpInstallable(name: "PHP 7.0", installed: nil, latest: "", actions: [.install]),
PhpInstallable(name: "PHP 5.6", installed: nil, latest: "", actions: [.install])
]).frame(width: 600, height: 500)
}
}