From 642e804e2882968ad580bbd87aea13079b245bb1 Mon Sep 17 00:00:00 2001 From: Dmitry Rodionov Date: Tue, 6 Sep 2016 21:28:24 +0700 Subject: [PATCH] Don't stop installing applications after a failure --- mas-cli/Commands/Install.swift | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mas-cli/Commands/Install.swift b/mas-cli/Commands/Install.swift index 14bb79a..87e45a6 100644 --- a/mas-cli/Commands/Install.swift +++ b/mas-cli/Commands/Install.swift @@ -12,13 +12,27 @@ struct InstallCommand: CommandType { let function = "Install from the Mac App Store" func run(options: Options) -> Result<(), MASError> { - for id in options.appIds { + // Try to download applications with given identifiers and collect results + let results = options.appIds.map { (id) -> Result<(), MASError> in if let error = download(id) { return .Failure(error) + } else { + return .Success() } } - - return .Success(()) + // See if at least one of the downloads failed + let errorIndex = results.indexOf { + if case .Failure(_) = $0 { + return true + } + return false + } + // And return an overrall general failure if there're failed downloads + if let _ = errorIndex { + return .Failure(MASError(code: .DownloadFailed)) + } else { + return .Success() + } } }