2
0
Fork 0
mirror of https://github.com/mas-cli/mas synced 2025-03-06 23:57:21 +00:00

Improve Upgrade.findOutdatedApps return type & use.

Partial 

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2025-01-02 10:48:17 -05:00
parent 60cd42fe31
commit 0831534307
No known key found for this signature in database

View file

@ -26,36 +26,35 @@ extension MAS {
}
func run(appLibrary: AppLibrary, searcher: AppStoreSearcher) throws {
let apps: [(installedApp: SoftwareProduct, storeApp: SearchResult)]
do {
apps = try findOutdatedApps(appLibrary: appLibrary, searcher: searcher)
let apps = try findOutdatedApps(appLibrary: appLibrary, searcher: searcher)
guard !apps.isEmpty else {
return
}
print("Upgrading \(apps.count) outdated application\(apps.count > 1 ? "s" : ""):")
print(
apps.map { installedApp, storeApp in
"\(storeApp.trackName) (\(installedApp.bundleVersion)) -> (\(storeApp.version))"
}
.joined(separator: "\n")
)
do {
try downloadApps(withAppIDs: apps.map(\.storeApp.trackId)).wait()
} catch {
throw error as? MASError ?? .downloadFailed(error: error as NSError)
}
} catch {
throw error as? MASError ?? .searchFailed
}
guard !apps.isEmpty else {
return
}
print("Upgrading \(apps.count) outdated application\(apps.count > 1 ? "s" : ""):")
print(
apps.map { installedApp, storeApp in
"\(storeApp.trackName) (\(installedApp.bundleVersion)) -> (\(storeApp.version))"
}
.joined(separator: "\n")
)
do {
try downloadApps(withAppIDs: apps.map(\.storeApp.trackId)).wait()
} catch {
throw error as? MASError ?? .downloadFailed(error: error as NSError)
}
}
private func findOutdatedApps(
appLibrary: AppLibrary,
searcher: AppStoreSearcher
) throws -> [(SoftwareProduct, SearchResult)] {
) throws -> [(installedApp: SoftwareProduct, storeApp: SearchResult)] {
let apps =
appIDOrNames.isEmpty
? appLibrary.installedApps