Skip to content

Commit

Permalink
Simplify Outdated.run(…).
Browse files Browse the repository at this point in the history
Resolve mas-cli#542

Signed-off-by: Ross Goldberg <[email protected]>
  • Loading branch information
rgoldberg committed Oct 14, 2024
1 parent cd42176 commit 0efd73a
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions Sources/mas/Commands/Outdated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,36 @@ extension Mas {
}

func run(appLibrary: AppLibrary, storeSearch: StoreSearch) throws {
let promises = appLibrary.installedApps.map { installedApp in
firstly {
storeSearch.lookup(app: installedApp.itemIdentifier.intValue)
}.done { storeApp in
guard let storeApp else {
if verbose {
printWarning(
"""
Identifier \(installedApp.itemIdentifier) not found in store. \
Was expected to identify \(installedApp.appName).
"""
)
}
return
}
_ = try when(
fulfilled:
appLibrary.installedApps.map { installedApp in
firstly {
storeSearch.lookup(app: installedApp.itemIdentifier.intValue)
}.done { storeApp in
guard let storeApp else {
if verbose {
printWarning(
"""
Identifier \(installedApp.itemIdentifier) not found in store. \
Was expected to identify \(installedApp.appName).
"""
)
}
return
}

if installedApp.isOutdatedWhenComparedTo(storeApp) {
print(
"""
\(installedApp.itemIdentifier) \(installedApp.appName) \
(\(installedApp.bundleVersion) -> \(storeApp.version))
"""
)
if installedApp.isOutdatedWhenComparedTo(storeApp) {
print(
"""
\(installedApp.itemIdentifier) \(installedApp.appName) \
(\(installedApp.bundleVersion) -> \(storeApp.version))
"""
)
}
}
}
}
}

_ = firstly {
when(fulfilled: promises)
}.map {
Result<Void, MASError>.success(())
}.recover { error in
.value(Result<Void, MASError>.failure(error as? MASError ?? .searchFailed))
}.wait()
)
.wait()
}
}
}

0 comments on commit 0efd73a

Please sign in to comment.