From 62a09bdbb744e42c17d0cdd1cc2aa4a6f830d425 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Wed, 28 Apr 2021 23:04:53 -0600 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=8A=20Log=20errors=20using=20print?= =?UTF-8?q?Error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/MasKit/Commands/Account.swift | 2 +- Sources/MasKit/Commands/List.swift | 2 +- Sources/MasKit/Commands/Lucky.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/MasKit/Commands/Account.swift b/Sources/MasKit/Commands/Account.swift index 9aba358e1..45249f7b1 100644 --- a/Sources/MasKit/Commands/Account.swift +++ b/Sources/MasKit/Commands/Account.swift @@ -27,7 +27,7 @@ public struct AccountCommand: CommandProtocol { if let account = ISStoreAccount.primaryAccount { print(String(describing: account.identifier)) } else { - print("Not signed in") + printError("Not signed in") return .failure(.notSignedIn) } return .success(()) diff --git a/Sources/MasKit/Commands/List.swift b/Sources/MasKit/Commands/List.swift index 3ba872abc..23752e73e 100644 --- a/Sources/MasKit/Commands/List.swift +++ b/Sources/MasKit/Commands/List.swift @@ -32,7 +32,7 @@ public struct ListCommand: CommandProtocol { public func run(_: Options) -> Result { let products = appLibrary.installedApps if products.isEmpty { - print("No installed apps found") + printError("No installed apps found") return .success(()) } diff --git a/Sources/MasKit/Commands/Lucky.swift b/Sources/MasKit/Commands/Lucky.swift index 8b35a90b1..f8288ab40 100644 --- a/Sources/MasKit/Commands/Lucky.swift +++ b/Sources/MasKit/Commands/Lucky.swift @@ -47,7 +47,7 @@ public struct LuckyCommand: CommandProtocol { do { let results = try storeSearch.search(for: options.appName).wait() guard let result = results.first else { - print("No results found") + printError("No results found") return .failure(.noSearchResultsFound) } From 892ad7e199da88b51f7ecf8c4ab6a7087a645e3d Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Mon, 3 Oct 2022 19:46:06 -0600 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=87=20Remove=20redundant=20error?= =?UTF-8?q?=20statements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/MasKit/Commands/Home.swift | 1 - Sources/MasKit/Commands/Info.swift | 1 - Sources/MasKit/Commands/Open.swift | 1 - Sources/MasKit/Commands/Search.swift | 1 - Sources/MasKit/Commands/Vendor.swift | 1 - 5 files changed, 5 deletions(-) diff --git a/Sources/MasKit/Commands/Home.swift b/Sources/MasKit/Commands/Home.swift index db7b1c397..f3f6bbbd5 100644 --- a/Sources/MasKit/Commands/Home.swift +++ b/Sources/MasKit/Commands/Home.swift @@ -39,7 +39,6 @@ public struct HomeCommand: CommandProtocol { public func run(_ options: HomeOptions) -> Result { do { guard let result = try storeSearch.lookup(app: options.appId).wait() else { - print("No results found") return .failure(.noSearchResultsFound) } diff --git a/Sources/MasKit/Commands/Info.swift b/Sources/MasKit/Commands/Info.swift index dc3ad35d8..82974dc61 100644 --- a/Sources/MasKit/Commands/Info.swift +++ b/Sources/MasKit/Commands/Info.swift @@ -30,7 +30,6 @@ public struct InfoCommand: CommandProtocol { public func run(_ options: InfoOptions) -> Result { do { guard let result = try storeSearch.lookup(app: options.appId).wait() else { - print("No results found") return .failure(.noSearchResultsFound) } diff --git a/Sources/MasKit/Commands/Open.swift b/Sources/MasKit/Commands/Open.swift index 0e31857b8..85e04dbcb 100644 --- a/Sources/MasKit/Commands/Open.swift +++ b/Sources/MasKit/Commands/Open.swift @@ -56,7 +56,6 @@ public struct OpenCommand: CommandProtocol { guard let result = try storeSearch.lookup(app: appId).wait() else { - print("No results found") return .failure(.noSearchResultsFound) } diff --git a/Sources/MasKit/Commands/Search.swift b/Sources/MasKit/Commands/Search.swift index 9800edd4e..cc0f2c74b 100644 --- a/Sources/MasKit/Commands/Search.swift +++ b/Sources/MasKit/Commands/Search.swift @@ -32,7 +32,6 @@ public struct SearchCommand: CommandProtocol { do { let results = try storeSearch.search(for: options.appName).wait() if results.isEmpty { - print("No results found") return .failure(.noSearchResultsFound) } diff --git a/Sources/MasKit/Commands/Vendor.swift b/Sources/MasKit/Commands/Vendor.swift index 07b9c357a..0fe84017e 100644 --- a/Sources/MasKit/Commands/Vendor.swift +++ b/Sources/MasKit/Commands/Vendor.swift @@ -40,7 +40,6 @@ public struct VendorCommand: CommandProtocol { do { guard let result = try storeSearch.lookup(app: options.appId).wait() else { - print("No results found") return .failure(.noSearchResultsFound) } From 0212a71adf936e638c4b5f3244e2e42b2033de9f Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sat, 8 Oct 2022 14:17:07 -0600 Subject: [PATCH 3/6] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20SwiftSyntax=20(0.50700?= =?UTF-8?q?.1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.resolved b/Package.resolved index ed761e539..23ad6e5a5 100644 --- a/Package.resolved +++ b/Package.resolved @@ -78,8 +78,8 @@ "repositoryURL": "https://github.com/apple/swift-syntax", "state": { "branch": null, - "revision": "04d4497be6b88e524a71778d828790e9589ae1c4", - "version": "0.50700.0" + "revision": "72d3da66b085c2299dd287c2be3b92b5ebd226de", + "version": "0.50700.1" } }, { From f54b1883c390fdd23268f2bf0c2eb4b2c3f25620 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sat, 8 Oct 2022 14:22:42 -0600 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=92=A1=20Document=20print=20utility?= =?UTF-8?q?=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/MasKit/Formatters/Utilities.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/MasKit/Formatters/Utilities.swift b/Sources/MasKit/Formatters/Utilities.swift index 2d1ce86fb..f76a8e647 100644 --- a/Sources/MasKit/Formatters/Utilities.swift +++ b/Sources/MasKit/Formatters/Utilities.swift @@ -79,6 +79,7 @@ extension FileHandle: TextOutputStream { } } +/// Prints a message to stdout prefixed with a blue arrow. func printInfo(_ message: String) { guard isatty(fileno(stdout)) != 0 else { print("==> \(message)") @@ -89,6 +90,7 @@ func printInfo(_ message: String) { print("\(csi)1;34m==>\(csi)0m \(csi)1m\(message)\(csi)0m") } +/// Prints a message to stderr prefixed with "Warning:" underlined in yellow. public func printWarning(_ message: String) { guard isatty(fileno(stderr)) != 0 else { print("Warning: \(message)", to: &standardError) @@ -99,6 +101,7 @@ public func printWarning(_ message: String) { print("\(csi)4;33mWarning:\(csi)0m \(message)", to: &standardError) } +/// Prints a message to stderr prefixed with "Error:" underlined in red. public func printError(_ message: String) { guard isatty(fileno(stderr)) != 0 else { print("Error: \(message)", to: &standardError) @@ -109,6 +112,7 @@ public func printError(_ message: String) { print("\(csi)4;31mError:\(csi)0m \(message)", to: &standardError) } +/// Flushes stdout. func clearLine() { guard isatty(fileno(stdout)) != 0 else { return From 610257f2929bb361ca0a143bb6ff215e6191b578 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sat, 8 Oct 2022 14:46:12 -0600 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=94=87=20Add=20--verbose=20flag=20to?= =?UTF-8?q?=20outdated=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/MasKit/Commands/Outdated.swift | 32 +++++++++++++++---- .../Commands/OutdatedCommandSpec.swift | 4 +-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Sources/MasKit/Commands/Outdated.swift b/Sources/MasKit/Commands/Outdated.swift index fcb26c24b..2bae89f40 100644 --- a/Sources/MasKit/Commands/Outdated.swift +++ b/Sources/MasKit/Commands/Outdated.swift @@ -15,7 +15,7 @@ import enum Swift.Result /// Command which displays a list of installed apps which have available updates /// ready to be installed from the Mac App Store. public struct OutdatedCommand: CommandProtocol { - public typealias Options = NoOptions + public typealias Options = OutdatedOptions public let verb = "outdated" public let function = "Lists pending updates from the Mac App Store" @@ -36,17 +36,19 @@ public struct OutdatedCommand: CommandProtocol { } /// Runs the command. - public func run(_: Options) -> Result { + public func run(_ options: Options) -> Result { let promises = appLibrary.installedApps.map { installedApp in firstly { storeSearch.lookup(app: installedApp.itemIdentifier.intValue) }.done { storeApp in guard let storeApp = storeApp else { - printWarning( - """ - Identifier \(installedApp.itemIdentifier) not found in store. \ - Was expected to identify \(installedApp.appName). - """) + if options.verbose { + printWarning( + """ + Identifier \(installedApp.itemIdentifier) not found in store. \ + Was expected to identify \(installedApp.appName). + """) + } return } @@ -70,3 +72,19 @@ public struct OutdatedCommand: CommandProtocol { }.wait() } } + + +public struct OutdatedOptions: OptionsProtocol { + public typealias ClientError = MASError + + let verbose: Bool + + static func create(verbose: Bool) -> OutdatedOptions { + OutdatedOptions(verbose: verbose) + } + + public static func evaluate(_ mode: CommandMode) -> Result> { + create + <*> mode <| Switch(flag: nil, key: "verbose", usage: "Show warnings about apps") + } +} diff --git a/Tests/MasKitTests/Commands/OutdatedCommandSpec.swift b/Tests/MasKitTests/Commands/OutdatedCommandSpec.swift index bc8d0cad5..6b7c72d10 100644 --- a/Tests/MasKitTests/Commands/OutdatedCommandSpec.swift +++ b/Tests/MasKitTests/Commands/OutdatedCommandSpec.swift @@ -19,9 +19,9 @@ public class OutdatedCommandSpec: QuickSpec { describe("outdated command") { it("displays apps with pending updates") { let cmd = OutdatedCommand() - let result = cmd.run(OutdatedCommand.Options()) + let result = cmd.run(OutdatedCommand.Options(verbose: true)) print(result) - // expect(result).to(beSuccess()) + expect(result).to(beSuccess()) } } } From 036dc05981f5dd5d91af749675fc325b41c7accb Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sat, 8 Oct 2022 14:49:42 -0600 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=9A=A8=20Remove=20extra=20linefeed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/MasKit/Commands/Outdated.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/MasKit/Commands/Outdated.swift b/Sources/MasKit/Commands/Outdated.swift index 2bae89f40..fbb1aa70d 100644 --- a/Sources/MasKit/Commands/Outdated.swift +++ b/Sources/MasKit/Commands/Outdated.swift @@ -73,7 +73,6 @@ public struct OutdatedCommand: CommandProtocol { } } - public struct OutdatedOptions: OptionsProtocol { public typealias ClientError = MASError