Add upgrade command to install pending updates

This commit is contained in:
Andrew Naylor 2015-12-30 21:03:45 +00:00
parent 4943fb0598
commit c3519ddd69
4 changed files with 51 additions and 1 deletions

View file

@ -34,6 +34,16 @@ Use `mas outdated` to list all applications with pending updates.
497799835 Xcode (7.0) 497799835 Xcode (7.0)
446107677 Screens VNC - Access Your Computer From Anywhere (3.6.7) 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 ## License
Code is under the MIT license. Code is under the MIT license.

View file

@ -25,7 +25,8 @@
ED0F238D1B8756E600AE40CD /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238C1B8756E600AE40CD /* Error.swift */; }; ED0F238D1B8756E600AE40CD /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238C1B8756E600AE40CD /* Error.swift */; };
ED0F23901B87A56F00AE40CD /* ISStoreAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238F1B87A56F00AE40CD /* ISStoreAccount.swift */; }; ED0F23901B87A56F00AE40CD /* ISStoreAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238F1B87A56F00AE40CD /* ISStoreAccount.swift */; };
EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDA3BE511B8B84AF00C18D70 /* SSPurchase.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 */; }; EDEAA0C01B51CE6200F2FC3F /* StoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */; };
EDEAA17D1B5C579100F2FC3F /* CommerceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */; }; EDEAA17D1B5C579100F2FC3F /* CommerceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -76,6 +77,7 @@
EDA3BE511B8B84AF00C18D70 /* SSPurchase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSPurchase.swift; sourceTree = "<group>"; }; EDA3BE511B8B84AF00C18D70 /* SSPurchase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SSPurchase.swift; sourceTree = "<group>"; };
EDB6CE8A1BAEB95100648B4D /* mas-cli-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "mas-cli-Info.plist"; sourceTree = "<group>"; }; EDB6CE8A1BAEB95100648B4D /* mas-cli-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "mas-cli-Info.plist"; sourceTree = "<group>"; };
EDB6CE8B1BAEC3D400648B4D /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; }; EDB6CE8B1BAEC3D400648B4D /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
EDD3B3621C34709400B56B88 /* Upgrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Upgrade.swift; sourceTree = "<group>"; };
EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreFoundation.framework; path = /System/Library/PrivateFrameworks/StoreFoundation.framework; sourceTree = "<absolute>"; }; EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreFoundation.framework; path = /System/Library/PrivateFrameworks/StoreFoundation.framework; sourceTree = "<absolute>"; };
EDEAA12C1B51CF8000F2FC3F /* mas-cli-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "mas-cli-Bridging-Header.h"; sourceTree = "<group>"; }; EDEAA12C1B51CF8000F2FC3F /* mas-cli-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "mas-cli-Bridging-Header.h"; sourceTree = "<group>"; };
EDEAA1311B5C576D00F2FC3F /* CKAccountStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKAccountStore.h; sourceTree = "<group>"; }; EDEAA1311B5C576D00F2FC3F /* CKAccountStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKAccountStore.h; sourceTree = "<group>"; };
@ -171,6 +173,7 @@
ED0F237E1B87522400AE40CD /* Install.swift */, ED0F237E1B87522400AE40CD /* Install.swift */,
ED0F23821B87533A00AE40CD /* List.swift */, ED0F23821B87533A00AE40CD /* List.swift */,
ED0F23841B87536A00AE40CD /* Outdated.swift */, ED0F23841B87536A00AE40CD /* Outdated.swift */,
EDD3B3621C34709400B56B88 /* Upgrade.swift */,
EDB6CE8B1BAEC3D400648B4D /* Version.swift */, EDB6CE8B1BAEC3D400648B4D /* Version.swift */,
); );
name = Commands; name = Commands;
@ -315,6 +318,7 @@
D40342B675C91E513F04B66E /* ResultType.swift in Sources */, D40342B675C91E513F04B66E /* ResultType.swift in Sources */,
EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */, EDA3BE521B8B84AF00C18D70 /* SSPurchase.swift in Sources */,
7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */, 7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */,
EDD3B3631C34709400B56B88 /* Upgrade.swift in Sources */,
EDB6CE8C1BAEC3D400648B4D /* Version.swift in Sources */, EDB6CE8C1BAEC3D400648B4D /* Version.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View file

@ -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<MASError>> {
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(())
}
}

View file

@ -20,6 +20,7 @@ registry.register(AccountCommand())
registry.register(InstallCommand()) registry.register(InstallCommand())
registry.register(ListCommand()) registry.register(ListCommand())
registry.register(OutdatedCommand()) registry.register(OutdatedCommand())
registry.register(UpgradeCommand())
registry.register(VersionCommand()) registry.register(VersionCommand())
registry.register(helpCommand) registry.register(helpCommand)