Cleanup code.

Partial #592

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2024-10-20 08:09:01 -04:00
parent 57da9e0f51
commit 3d9ea972f9
No known key found for this signature in database
8 changed files with 11 additions and 11 deletions

View file

@ -36,7 +36,7 @@ func downloadAll(_ appIDs: [AppID], purchase: Bool = false) -> Promise<Void> {
private func downloadWithRetries(_ appID: AppID, purchase: Bool = false, attempts: Int = 3) -> Promise<Void> {
SSPurchase().perform(appID: appID, purchase: purchase)
.recover { error -> Promise<Void> in
.recover { error in
guard attempts > 1 else {
throw error
}

View file

@ -10,8 +10,6 @@ import ArgumentParser
import Foundation
import PromiseKit
import enum Swift.Result
extension Mas {
/// Command which displays a list of installed apps which have available updates
/// ready to be installed from the Mac App Store.

View file

@ -45,7 +45,7 @@ class MasStoreSearch: StoreSearch {
entities += [.iPadSoftware, .iPhoneSoftware]
}
let results = entities.map { entity -> Promise<[SearchResult]> in
let results = entities.map { entity in
guard let url = searchURL(for: appName, inCountry: country, ofEntity: entity) else {
fatalError("Failed to build URL for \(appName)")
}
@ -70,7 +70,8 @@ class MasStoreSearch: StoreSearch {
}
return firstly {
loadSearchResults(url)
}.then { results -> Guarantee<SearchResult?> in
}
.then { results -> Guarantee<SearchResult?> in
guard let result = results.first else {
return .value(nil)
}
@ -104,7 +105,8 @@ class MasStoreSearch: StoreSearch {
private func loadSearchResults(_ url: URL) -> Promise<[SearchResult]> {
firstly {
networkManager.loadData(from: url)
}.map { data -> [SearchResult] in
}
.map { data in
do {
return try JSONDecoder().decode(SearchResultList.self, from: data).results
} catch {

View file

@ -69,7 +69,7 @@ func captureStream(
_ stream: UnsafeMutablePointer<FILE>,
encoding: String.Encoding = .utf8,
_ block: @escaping () throws -> Void
) throws -> String {
) rethrows -> String {
let originalFd = fileno(stream)
let duplicateFd = dup(originalFd)
defer {

View file

@ -70,7 +70,7 @@ public class UninstallSpec: QuickSpec {
== "==> Some App /tmp/Some.app\n==> (not removed, dry run)\n"
}
it("fails if there is a problem with the trash command") {
var brokenUninstall = app // make mutable copy
var brokenUninstall = app
brokenUninstall.bundlePath = "/dev/null"
mockLibrary.installedApps.append(brokenUninstall)
expect {

View file

@ -24,7 +24,7 @@ public class VersionSpec: QuickSpec {
try Mas.Version.parse([]).run()
}
}
== Package.version + "\n"
== "\(Package.version)\n"
}
}
}

View file

@ -9,7 +9,7 @@
@testable import mas
class AppLibraryMock: AppLibrary {
var installedApps = [SoftwareProduct]()
var installedApps: [SoftwareProduct] = []
func uninstallApp(app: SoftwareProduct) throws {
if !installedApps.contains(where: { product -> Bool in

View file

@ -22,7 +22,7 @@ class MASErrorTestCase: XCTestCase {
var localizedDescription: String {
get { "dummy value" }
set {
NSError.setUserInfoValueProvider(forDomain: errorDomain) { (_: Error, _: String) -> Any? in
NSError.setUserInfoValueProvider(forDomain: errorDomain) { _, _ in
newValue
}
}