mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 03:23:08 +00:00
Cleanup code.
Partial #592 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
parent
57da9e0f51
commit
3d9ea972f9
8 changed files with 11 additions and 11 deletions
|
@ -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> {
|
private func downloadWithRetries(_ appID: AppID, purchase: Bool = false, attempts: Int = 3) -> Promise<Void> {
|
||||||
SSPurchase().perform(appID: appID, purchase: purchase)
|
SSPurchase().perform(appID: appID, purchase: purchase)
|
||||||
.recover { error -> Promise<Void> in
|
.recover { error in
|
||||||
guard attempts > 1 else {
|
guard attempts > 1 else {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import ArgumentParser
|
||||||
import Foundation
|
import Foundation
|
||||||
import PromiseKit
|
import PromiseKit
|
||||||
|
|
||||||
import enum Swift.Result
|
|
||||||
|
|
||||||
extension Mas {
|
extension Mas {
|
||||||
/// Command which displays a list of installed apps which have available updates
|
/// Command which displays a list of installed apps which have available updates
|
||||||
/// ready to be installed from the Mac App Store.
|
/// ready to be installed from the Mac App Store.
|
||||||
|
|
|
@ -45,7 +45,7 @@ class MasStoreSearch: StoreSearch {
|
||||||
entities += [.iPadSoftware, .iPhoneSoftware]
|
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 {
|
guard let url = searchURL(for: appName, inCountry: country, ofEntity: entity) else {
|
||||||
fatalError("Failed to build URL for \(appName)")
|
fatalError("Failed to build URL for \(appName)")
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,8 @@ class MasStoreSearch: StoreSearch {
|
||||||
}
|
}
|
||||||
return firstly {
|
return firstly {
|
||||||
loadSearchResults(url)
|
loadSearchResults(url)
|
||||||
}.then { results -> Guarantee<SearchResult?> in
|
}
|
||||||
|
.then { results -> Guarantee<SearchResult?> in
|
||||||
guard let result = results.first else {
|
guard let result = results.first else {
|
||||||
return .value(nil)
|
return .value(nil)
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,8 @@ class MasStoreSearch: StoreSearch {
|
||||||
private func loadSearchResults(_ url: URL) -> Promise<[SearchResult]> {
|
private func loadSearchResults(_ url: URL) -> Promise<[SearchResult]> {
|
||||||
firstly {
|
firstly {
|
||||||
networkManager.loadData(from: url)
|
networkManager.loadData(from: url)
|
||||||
}.map { data -> [SearchResult] in
|
}
|
||||||
|
.map { data in
|
||||||
do {
|
do {
|
||||||
return try JSONDecoder().decode(SearchResultList.self, from: data).results
|
return try JSONDecoder().decode(SearchResultList.self, from: data).results
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -69,7 +69,7 @@ func captureStream(
|
||||||
_ stream: UnsafeMutablePointer<FILE>,
|
_ stream: UnsafeMutablePointer<FILE>,
|
||||||
encoding: String.Encoding = .utf8,
|
encoding: String.Encoding = .utf8,
|
||||||
_ block: @escaping () throws -> Void
|
_ block: @escaping () throws -> Void
|
||||||
) throws -> String {
|
) rethrows -> String {
|
||||||
let originalFd = fileno(stream)
|
let originalFd = fileno(stream)
|
||||||
let duplicateFd = dup(originalFd)
|
let duplicateFd = dup(originalFd)
|
||||||
defer {
|
defer {
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class UninstallSpec: QuickSpec {
|
||||||
== "==> Some App /tmp/Some.app\n==> (not removed, dry run)\n"
|
== "==> Some App /tmp/Some.app\n==> (not removed, dry run)\n"
|
||||||
}
|
}
|
||||||
it("fails if there is a problem with the trash command") {
|
it("fails if there is a problem with the trash command") {
|
||||||
var brokenUninstall = app // make mutable copy
|
var brokenUninstall = app
|
||||||
brokenUninstall.bundlePath = "/dev/null"
|
brokenUninstall.bundlePath = "/dev/null"
|
||||||
mockLibrary.installedApps.append(brokenUninstall)
|
mockLibrary.installedApps.append(brokenUninstall)
|
||||||
expect {
|
expect {
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class VersionSpec: QuickSpec {
|
||||||
try Mas.Version.parse([]).run()
|
try Mas.Version.parse([]).run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
== Package.version + "\n"
|
== "\(Package.version)\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
@testable import mas
|
@testable import mas
|
||||||
|
|
||||||
class AppLibraryMock: AppLibrary {
|
class AppLibraryMock: AppLibrary {
|
||||||
var installedApps = [SoftwareProduct]()
|
var installedApps: [SoftwareProduct] = []
|
||||||
|
|
||||||
func uninstallApp(app: SoftwareProduct) throws {
|
func uninstallApp(app: SoftwareProduct) throws {
|
||||||
if !installedApps.contains(where: { product -> Bool in
|
if !installedApps.contains(where: { product -> Bool in
|
||||||
|
|
|
@ -22,7 +22,7 @@ class MASErrorTestCase: XCTestCase {
|
||||||
var localizedDescription: String {
|
var localizedDescription: String {
|
||||||
get { "dummy value" }
|
get { "dummy value" }
|
||||||
set {
|
set {
|
||||||
NSError.setUserInfoValueProvider(forDomain: errorDomain) { (_: Error, _: String) -> Any? in
|
NSError.setUserInfoValueProvider(forDomain: errorDomain) { _, _ in
|
||||||
newValue
|
newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue