From 64ab55718afd96dddb2b18591db2c395a1d71c15 Mon Sep 17 00:00:00 2001 From: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> Date: Tue, 29 Oct 2024 03:38:12 -0400 Subject: [PATCH] Improve `upgrade` unknown app ID/name error output. Don't output a warning if nothing requires an upgrade. Partial #533 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> --- Sources/mas/Commands/Upgrade.swift | 17 ++++++++++++----- Tests/masTests/Commands/UpgradeSpec.swift | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Sources/mas/Commands/Upgrade.swift b/Sources/mas/Commands/Upgrade.swift index 4823976..21ec1ba 100644 --- a/Sources/mas/Commands/Upgrade.swift +++ b/Sources/mas/Commands/Upgrade.swift @@ -35,7 +35,6 @@ extension MAS { } guard !apps.isEmpty else { - printWarning("Nothing found to upgrade") return } @@ -59,14 +58,22 @@ extension MAS { let apps = appIDOrNames.isEmpty ? appLibrary.installedApps - : appIDOrNames.flatMap { appID in - if let appID = AppID(appID) { + : appIDOrNames.flatMap { appIDOrName in + if let appID = AppID(appIDOrName) { // argument is an AppID, lookup apps by id using argument - return appLibrary.installedApps(withAppID: appID) + let installedApps = appLibrary.installedApps(withAppID: appID) + if installedApps.isEmpty { + printError("Unknown app ID \(appID)") + } + return installedApps } // argument is not an AppID, lookup apps by name using argument - return appLibrary.installedApps(named: appID) + let installedApps = appLibrary.installedApps(named: appIDOrName) + if installedApps.isEmpty { + printError("Unknown app name '\(appIDOrName)'") + } + return installedApps } let promises = apps.map { installedApp in diff --git a/Tests/masTests/Commands/UpgradeSpec.swift b/Tests/masTests/Commands/UpgradeSpec.swift index 6630777..c3a805f 100644 --- a/Tests/masTests/Commands/UpgradeSpec.swift +++ b/Tests/masTests/Commands/UpgradeSpec.swift @@ -25,7 +25,7 @@ public class UpgradeSpec: QuickSpec { .run(appLibrary: MockAppLibrary(), searcher: MockAppStoreSearcher()) } } - == "Warning: Nothing found to upgrade\n" + .toNot(throwError()) } } }