mirror of
https://github.com/mas-cli/mas
synced 2024-11-25 13:00:23 +00:00
🎨 Format source
# Conflicts: # MasKitTests/Formatters/AppListFormatterSpec.swift
This commit is contained in:
parent
ca52e895a4
commit
3ffa99d418
13 changed files with 45 additions and 45 deletions
|
@ -21,7 +21,7 @@ func download(_ adamId: UInt64, purchase: Bool = false) -> MASError? {
|
|||
}
|
||||
|
||||
guard let storeAccount = account as? ISStoreAccount
|
||||
else { fatalError("Unable to cast StoreAccount to ISStoreAccount") }
|
||||
else { fatalError("Unable to cast StoreAccount to ISStoreAccount") }
|
||||
let purchase = SSPurchase(adamId: adamId, account: storeAccount, purchase: purchase)
|
||||
|
||||
var purchaseError: MASError?
|
||||
|
|
|
@ -20,8 +20,8 @@ import StoreFoundation
|
|||
|
||||
func downloadQueue(_ queue: CKDownloadQueue, statusChangedFor download: SSDownload) {
|
||||
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
|
||||
let status = download.status else {
|
||||
return
|
||||
let status = download.status else {
|
||||
return
|
||||
}
|
||||
|
||||
if status.isFailed || status.isCancelled {
|
||||
|
@ -41,8 +41,8 @@ import StoreFoundation
|
|||
|
||||
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
|
||||
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
|
||||
let status = download.status else {
|
||||
return
|
||||
let status = download.status else {
|
||||
return
|
||||
}
|
||||
|
||||
clearLine()
|
||||
|
|
|
@ -39,20 +39,20 @@ public struct OpenCommand: CommandProtocol {
|
|||
}
|
||||
|
||||
guard let appId = Int(options.appId)
|
||||
else {
|
||||
print("Invalid app ID")
|
||||
return .failure(.noSearchResultsFound)
|
||||
else {
|
||||
print("Invalid app ID")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
guard let result = try storeSearch.lookup(app: appId)
|
||||
else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
guard var url = URLComponents(string: result.trackViewUrl)
|
||||
else {
|
||||
return .failure(.searchFailed)
|
||||
else {
|
||||
return .failure(.searchFailed)
|
||||
}
|
||||
url.scheme = masScheme
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public struct SignInOptions: OptionsProtocol {
|
|||
static func create(username: String) -> (_ password: String) -> (_ dialog: Bool) -> SignInOptions {
|
||||
return { password in { dialog in
|
||||
SignInOptions(username: username, password: password, dialog: dialog)
|
||||
} }
|
||||
} }
|
||||
}
|
||||
|
||||
public static func evaluate(_ mode: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
|
||||
|
|
|
@ -30,13 +30,13 @@ public struct VendorCommand: CommandProtocol {
|
|||
public func run(_ options: VendorOptions) -> Result<(), MASError> {
|
||||
do {
|
||||
guard let result = try storeSearch.lookup(app: options.appId)
|
||||
else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
guard let vendorWebsite = result.sellerUrl
|
||||
else { throw MASError.noVendorWebsite }
|
||||
else { throw MASError.noVendorWebsite }
|
||||
|
||||
do {
|
||||
try openCommand.run(arguments: vendorWebsite)
|
||||
|
|
|
@ -22,17 +22,17 @@ public class MasStoreSearch: StoreSearch {
|
|||
/// - Throws: Error if there is a problem with the network request.
|
||||
public func search(for appName: String) throws -> SearchResultList {
|
||||
guard let url = searchURL(for: appName)
|
||||
else { throw MASError.urlEncoding }
|
||||
else { throw MASError.urlEncoding }
|
||||
|
||||
let result = networkManager.loadDataSync(from: url)
|
||||
|
||||
// Unwrap network result
|
||||
guard case let .success(data) = result
|
||||
else {
|
||||
if case let .failure(error) = result {
|
||||
throw error
|
||||
}
|
||||
throw MASError.noData
|
||||
else {
|
||||
if case let .failure(error) = result {
|
||||
throw error
|
||||
}
|
||||
throw MASError.noData
|
||||
}
|
||||
|
||||
do {
|
||||
|
@ -50,24 +50,24 @@ public class MasStoreSearch: StoreSearch {
|
|||
/// - Throws: Error if there is a problem with the network request.
|
||||
public func lookup(app appId: Int) throws -> SearchResult? {
|
||||
guard let url = lookupURL(forApp: appId)
|
||||
else { throw MASError.urlEncoding }
|
||||
else { throw MASError.urlEncoding }
|
||||
|
||||
let result = networkManager.loadDataSync(from: url)
|
||||
|
||||
// Unwrap network result
|
||||
guard case let .success(data) = result
|
||||
else {
|
||||
if case let .failure(error) = result {
|
||||
throw error
|
||||
}
|
||||
throw MASError.noData
|
||||
else {
|
||||
if case let .failure(error) = result {
|
||||
throw error
|
||||
}
|
||||
throw MASError.noData
|
||||
}
|
||||
|
||||
do {
|
||||
let results = try JSONDecoder().decode(SearchResultList.self, from: data)
|
||||
|
||||
guard let searchResult = results.results.first
|
||||
else { return nil }
|
||||
else { return nil }
|
||||
|
||||
return searchResult
|
||||
} catch {
|
||||
|
|
|
@ -42,7 +42,7 @@ extension MASError: CustomStringConvertible {
|
|||
return "The 'signin' command has been disabled on this macOS version. " +
|
||||
"Please sign into the Mac App Store app manually." +
|
||||
"\nFor more info see: " +
|
||||
"https://github.com/mas-cli/mas/issues/164"
|
||||
"https://github.com/mas-cli/mas/issues/164"
|
||||
|
||||
case let .signInFailed(error):
|
||||
if let error = error {
|
||||
|
|
|
@ -19,7 +19,7 @@ struct AppInfoFormatter {
|
|||
"\(app.trackName)",
|
||||
"\(app.version)",
|
||||
"[\(app.price)]"
|
||||
].joined(separator: " ")
|
||||
].joined(separator: " ")
|
||||
|
||||
return [
|
||||
headline,
|
||||
|
@ -28,7 +28,7 @@ struct AppInfoFormatter {
|
|||
"Minimum OS: \(app.minimumOsVersion)",
|
||||
"Size: \(humanReadableSize(app.fileSizeBytes))",
|
||||
"From: \(app.trackViewUrl)"
|
||||
].joined(separator: "\n")
|
||||
].joined(separator: "\n")
|
||||
}
|
||||
|
||||
/// Formats a file size.
|
||||
|
|
|
@ -23,7 +23,7 @@ class StoreSearchMock: StoreSearch {
|
|||
}
|
||||
|
||||
guard let result = apps[appId]
|
||||
else { throw MASError.noSearchResultsFound }
|
||||
else { throw MASError.noSearchResultsFound }
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ class StoreSearchSpec: QuickSpec {
|
|||
let appName = "myapp"
|
||||
let urlString = storeSearch.searchURLString(forApp: appName)
|
||||
expect(urlString) ==
|
||||
"https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appName)"
|
||||
"https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appName)"
|
||||
}
|
||||
it("contains the encoded app name") {
|
||||
let appName = "My App"
|
||||
let appNameEncoded = "My%20App"
|
||||
let urlString = storeSearch.searchURLString(forApp: appName)
|
||||
expect(urlString) ==
|
||||
"https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appNameEncoded)"
|
||||
"https://itunes.apple.com/search?media=software&entity=macSoftware&term=\(appNameEncoded)"
|
||||
}
|
||||
// Find a character that causes addingPercentEncoding(withAllowedCharacters to return nil
|
||||
xit("is nil when app name cannot be url encoded") {
|
||||
|
|
|
@ -30,7 +30,7 @@ class SearchResultsFormatterSpec: QuickSpec {
|
|||
trackId: 12345,
|
||||
trackName: "Awesome App",
|
||||
version: "19.2.1"
|
||||
)]
|
||||
)]
|
||||
let output = format(results, false)
|
||||
expect(output) == " 12345 Awesome App (19.2.1)"
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class SearchResultsFormatterSpec: QuickSpec {
|
|||
trackId: 12345,
|
||||
trackName: "Awesome App",
|
||||
version: "19.2.1"
|
||||
)]
|
||||
)]
|
||||
let output = format(results, true)
|
||||
expect(output) == " 12345 Awesome App $ 9.87 (19.2.1)"
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class SearchResultsFormatterSpec: QuickSpec {
|
|||
]
|
||||
let output = format(results, false)
|
||||
expect(output) ==
|
||||
" 12345 Awesome App (19.2.1)\n 67890 Even Better App (1.2.0)"
|
||||
" 12345 Awesome App (19.2.1)\n 67890 Even Better App (1.2.0)"
|
||||
}
|
||||
it("can format a two results with prices") {
|
||||
results = [
|
||||
|
@ -80,7 +80,7 @@ class SearchResultsFormatterSpec: QuickSpec {
|
|||
]
|
||||
let output = format(results, true)
|
||||
expect(output) ==
|
||||
" 12345 Awesome App $ 9.87 (19.2.1)\n 67890 Even Better App $ 0.01 (1.2.0)"
|
||||
" 12345 Awesome App $ 9.87 (19.2.1)\n 67890 Even Better App $ 0.01 (1.2.0)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ class TestURLSessionDelegate: NSObject, URLSessionDelegate {
|
|||
func urlSession(_: URLSession,
|
||||
didReceive challenge: URLAuthenticationChallenge,
|
||||
completionHandler: (URLSession.AuthChallengeDisposition,
|
||||
URLCredential?) -> Void) {
|
||||
URLCredential?) -> Void) {
|
||||
|
||||
// For example, you may want to override this to accept some self-signed certs here.
|
||||
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust,
|
||||
Constants.selfSignedHosts.contains(challenge.protectionSpace.host) {
|
||||
Constants.selfSignedHosts.contains(challenge.protectionSpace.host) {
|
||||
// Allow the self-signed cert.
|
||||
let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
|
||||
completionHandler(.useCredential, credential)
|
||||
|
|
|
@ -13,7 +13,7 @@ import Nimble
|
|||
func beSuccess() -> Predicate<Result<(), MASError>> {
|
||||
return Predicate.define("be <success>") { expression, message in
|
||||
if let actual = try expression.evaluate(),
|
||||
case .success = actual {
|
||||
case .success = actual {
|
||||
return PredicateResult(status: .matches, message: message)
|
||||
}
|
||||
return PredicateResult(status: .fail, message: message)
|
||||
|
@ -24,7 +24,7 @@ func beSuccess() -> Predicate<Result<(), MASError>> {
|
|||
func beFailure(test: @escaping (MASError) -> Void = { _ in }) -> Predicate<Result<(), MASError>> {
|
||||
return Predicate.define("be <failure>") { expression, message in
|
||||
if let actual = try expression.evaluate(),
|
||||
case let .failure(error) = actual {
|
||||
case let .failure(error) = actual {
|
||||
test(error)
|
||||
return PredicateResult(status: .matches, message: message)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue