From c3519ddd696a6fd0eeedd10947ca91347c4ff941 Mon Sep 17 00:00:00 2001 From: Andrew Naylor Date: Wed, 30 Dec 2015 21:03:45 +0000 Subject: [PATCH] Add `upgrade` command to install pending updates --- README.md | 10 +++++++++ mas-cli.xcodeproj/project.pbxproj | 6 +++++- mas-cli/Commands/Upgrade.swift | 35 +++++++++++++++++++++++++++++++ mas-cli/main.swift | 1 + 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 mas-cli/Commands/Upgrade.swift diff --git a/README.md b/README.md index 6ee9b9a..055cc4c 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,16 @@ Use `mas outdated` to list all applications with pending updates. 497799835 Xcode (7.0) 446107677 Screens VNC - Access Your Computer From Anywhere (3.6.7) +To install all pending updates run `mas upgrade`. + + $ mas upgrade + Upgrading 2 outdated applications: + Xcode (7.0), Screens VNC - Access Your Computer From Anywhere (3.6.7) + ==> Downloading Xcode + ==> Installed Xcode + ==> Downloading iFlicks + ==> Installed iFlicks + ## License Code is under the MIT license. diff --git a/mas-cli.xcodeproj/project.pbxproj b/mas-cli.xcodeproj/project.pbxproj index a4408f6..6b40171 100644 --- a/mas-cli.xcodeproj/project.pbxproj +++ b/mas-cli.xcodeproj/project.pbxproj @@ -25,7 +25,8 @@ ED0F238D1B8756E600AE40CD /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238C1B8756E600AE40CD /* Error.swift */; }; ED0F23901B87A56F00AE40CD /* ISStoreAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238F1B87A56F00AE40CD /* ISStoreAccount.swift */; }; EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA3BE511B8B84AF00C18D70 /* SSPurchase.swift */; }; - EDB6CE8C1BAEC3D400648B4D /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB6CE8B1BAEC3D400648B4D /* Version.swift */; settings = {ASSET_TAGS = (); }; }; + EDB6CE8C1BAEC3D400648B4D /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDB6CE8B1BAEC3D400648B4D /* Version.swift */; }; + EDD3B3631C34709400B56B88 /* Upgrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDD3B3621C34709400B56B88 /* Upgrade.swift */; }; EDEAA0C01B51CE6200F2FC3F /* StoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */; }; EDEAA17D1B5C579100F2FC3F /* CommerceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */; }; /* End PBXBuildFile section */ @@ -76,6 +77,7 @@ EDA3BE511B8B84AF00C18D70 /* SSPurchase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSPurchase.swift; sourceTree = ""; }; EDB6CE8A1BAEB95100648B4D /* mas-cli-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "mas-cli-Info.plist"; sourceTree = ""; }; EDB6CE8B1BAEC3D400648B4D /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; + EDD3B3621C34709400B56B88 /* Upgrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Upgrade.swift; sourceTree = ""; }; EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreFoundation.framework; path = /System/Library/PrivateFrameworks/StoreFoundation.framework; sourceTree = ""; }; EDEAA12C1B51CF8000F2FC3F /* mas-cli-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "mas-cli-Bridging-Header.h"; sourceTree = ""; }; EDEAA1311B5C576D00F2FC3F /* CKAccountStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKAccountStore.h; sourceTree = ""; }; @@ -171,6 +173,7 @@ ED0F237E1B87522400AE40CD /* Install.swift */, ED0F23821B87533A00AE40CD /* List.swift */, ED0F23841B87536A00AE40CD /* Outdated.swift */, + EDD3B3621C34709400B56B88 /* Upgrade.swift */, EDB6CE8B1BAEC3D400648B4D /* Version.swift */, ); name = Commands; @@ -315,6 +318,7 @@ D40342B675C91E513F04B66E /* ResultType.swift in Sources */, EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */, 7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */, + EDD3B3631C34709400B56B88 /* Upgrade.swift in Sources */, EDB6CE8C1BAEC3D400648B4D /* Version.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/mas-cli/Commands/Upgrade.swift b/mas-cli/Commands/Upgrade.swift new file mode 100644 index 0000000..80a59e2 --- /dev/null +++ b/mas-cli/Commands/Upgrade.swift @@ -0,0 +1,35 @@ +// +// Upgrade.swift +// mas-cli +// +// Created by Andrew Naylor on 30/12/2015. +// Copyright © 2015 Andrew Naylor. All rights reserved. +// + +struct UpgradeCommand: CommandType { + let verb = "upgrade" + let function = "Performs all pending updates from the Mac App Store" + + func run(mode: CommandMode) -> Result<(), CommandantError> { + switch mode { + case .Arguments: + let updateController = CKUpdateController.sharedUpdateController() + + guard let updates = updateController.availableUpdates() where updates.count > 0 else { + print("Everything is up-to-date") + break + } + + print("Upgrading \(updates.count) outdated application\(updates.count > 1 ? "s" : ""):") + print(updates.map({ "\($0.title) (\($0.bundleVersion))" }).joinWithSeparator(", ")) + for update in updates { + if let error = download(UInt64(update.itemIdentifier.intValue)) { + return .Failure(CommandantError.CommandError(error)) + } + } + default: + break + } + return .Success(()) + } +} \ No newline at end of file diff --git a/mas-cli/main.swift b/mas-cli/main.swift index 1591631..080e3c4 100644 --- a/mas-cli/main.swift +++ b/mas-cli/main.swift @@ -20,6 +20,7 @@ registry.register(AccountCommand()) registry.register(InstallCommand()) registry.register(ListCommand()) registry.register(OutdatedCommand()) +registry.register(UpgradeCommand()) registry.register(VersionCommand()) registry.register(helpCommand)