mas/mas-cli/Commands/List.swift
Andrew Naylor 1e1a80aa58 Guard against nil for allProducts
This usually happens when `mas` is called outside of the user namespace
2016-04-17 01:18:14 +01:00

25 lines
No EOL
741 B
Swift

//
// List.swift
// mas-cli
//
// Created by Andrew Naylor on 21/08/2015.
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
//
struct ListCommand: CommandType {
typealias Options = NoOptions<MASError>
let verb = "list"
let function = "Lists apps from the Mac App Store which are currently installed"
func run(options: Options) -> Result<(), MASError> {
let softwareMap = CKSoftwareMap.sharedSoftwareMap()
guard let products = softwareMap.allProducts() else {
print("No installed apps found")
return .Success(())
}
for product in products {
print("\(product.itemIdentifier) \(product.appName)")
}
return .Success(())
}
}