mirror of
https://github.com/mas-cli/mas
synced 2024-11-25 13:00:23 +00:00
🈺 Make MasKit types and members public
This commit is contained in:
parent
e3451e5b85
commit
6b1b5bd00a
14 changed files with 118 additions and 96 deletions
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import StoreFoundation
|
||||
|
||||
struct AccountCommand: CommandProtocol {
|
||||
typealias Options = NoOptions<MASError>
|
||||
let verb = "account"
|
||||
let function = "Prints the primary account Apple ID"
|
||||
public struct AccountCommand: CommandProtocol {
|
||||
public typealias Options = NoOptions<MASError>
|
||||
public let verb = "account"
|
||||
public let function = "Prints the primary account Apple ID"
|
||||
|
||||
public init() {}
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
if let account = ISStoreAccount.primaryAccount {
|
||||
print(String(describing: account.identifier))
|
||||
}
|
||||
|
|
|
@ -10,11 +10,13 @@ import Commandant
|
|||
import Result
|
||||
import Foundation
|
||||
|
||||
struct InfoCommand: CommandProtocol {
|
||||
let verb = "info"
|
||||
let function = "Display app information from the Mac App Store"
|
||||
public struct InfoCommand: CommandProtocol {
|
||||
public let verb = "info"
|
||||
public let function = "Display app information from the Mac App Store"
|
||||
|
||||
func run(_ options: InfoOptions) -> Result<(), MASError> {
|
||||
public init() {}
|
||||
|
||||
public func run(_ options: InfoOptions) -> Result<(), MASError> {
|
||||
guard let infoURLString = infoURLString(options.appId),
|
||||
let searchJson = URLSession.requestSynchronousJSONWithURLString(infoURLString) as? [String: Any] else {
|
||||
return .failure(.searchFailed)
|
||||
|
@ -40,21 +42,20 @@ struct InfoCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
struct InfoOptions: OptionsProtocol {
|
||||
public struct InfoOptions: OptionsProtocol {
|
||||
let appId: String
|
||||
|
||||
static func create(_ appId: String) -> InfoOptions {
|
||||
return InfoOptions(appId: appId)
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<InfoOptions, CommandantError<MASError>> {
|
||||
public static func evaluate(_ m: CommandMode) -> Result<InfoOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Argument(usage: "the app id to show info")
|
||||
}
|
||||
}
|
||||
|
||||
private struct AppInfoFormatter {
|
||||
|
||||
private enum Keys {
|
||||
static let Name = "trackCensoredName"
|
||||
static let Version = "version"
|
||||
|
|
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import CommerceKit
|
||||
|
||||
struct InstallCommand: CommandProtocol {
|
||||
typealias Options = InstallOptions
|
||||
let verb = "install"
|
||||
let function = "Install from the Mac App Store"
|
||||
public struct InstallCommand: CommandProtocol {
|
||||
public typealias Options = InstallOptions
|
||||
public let verb = "install"
|
||||
public let function = "Install from the Mac App Store"
|
||||
|
||||
public init() {}
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
// Try to download applications with given identifiers and collect results
|
||||
let downloadResults = options.appIds.compactMap { (appId) -> MASError? in
|
||||
if let product = installedApp(appId) , !options.forceInstall {
|
||||
|
@ -44,17 +46,17 @@ struct InstallCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
struct InstallOptions: OptionsProtocol {
|
||||
public struct InstallOptions: OptionsProtocol {
|
||||
let appIds: [UInt64]
|
||||
let forceInstall: Bool
|
||||
|
||||
static func create(_ appIds: [Int]) -> (_ forceInstall: Bool) -> InstallOptions {
|
||||
|
||||
public static func create(_ appIds: [Int]) -> (_ forceInstall: Bool) -> InstallOptions {
|
||||
return { forceInstall in
|
||||
return InstallOptions(appIds: appIds.map{UInt64($0)}, forceInstall: forceInstall)
|
||||
}
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<InstallOptions, CommandantError<MASError>> {
|
||||
|
||||
public static func evaluate(_ m: CommandMode) -> Result<InstallOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Argument(usage: "app ID(s) to install")
|
||||
<*> m <| Switch(flag: nil, key: "force", usage: "force reinstall")
|
||||
|
|
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import CommerceKit
|
||||
|
||||
struct ListCommand: CommandProtocol {
|
||||
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> {
|
||||
public struct ListCommand: CommandProtocol {
|
||||
public typealias Options = NoOptions<MASError>
|
||||
public let verb = "list"
|
||||
public let function = "Lists apps from the Mac App Store which are currently installed"
|
||||
|
||||
public init() {}
|
||||
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
let softwareMap = CKSoftwareMap.shared()
|
||||
guard let products = softwareMap.allProducts() else {
|
||||
print("No installed apps found")
|
||||
|
|
|
@ -11,12 +11,14 @@ import Result
|
|||
|
||||
import CommerceKit
|
||||
|
||||
struct LuckyCommand: CommandProtocol {
|
||||
typealias Options = LuckyOptions
|
||||
let verb = "lucky"
|
||||
let function = "Install the first result from the Mac App Store"
|
||||
public struct LuckyCommand: CommandProtocol {
|
||||
public typealias Options = LuckyOptions
|
||||
public let verb = "lucky"
|
||||
public let function = "Install the first result from the Mac App Store"
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public init() {}
|
||||
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
|
||||
guard let searchURLString = searchURLString(options.appName),
|
||||
let searchJson = URLSession.requestSynchronousJSONWithURLString(searchURLString) as? [String: Any] else {
|
||||
|
@ -71,20 +73,19 @@ struct LuckyCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
struct LuckyOptions: OptionsProtocol {
|
||||
public struct LuckyOptions: OptionsProtocol {
|
||||
let appName: String
|
||||
let forceInstall: Bool
|
||||
|
||||
static func create(_ appName: String) -> (_ forceInstall: Bool) -> LuckyOptions {
|
||||
|
||||
public static func create(_ appName: String) -> (_ forceInstall: Bool) -> LuckyOptions {
|
||||
return { forceInstall in
|
||||
return LuckyOptions(appName: appName, forceInstall: forceInstall)
|
||||
}
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<LuckyOptions, CommandantError<MASError>> {
|
||||
|
||||
public static func evaluate(_ m: CommandMode) -> Result<LuckyOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Argument(usage: "the app name to install")
|
||||
<*> m <| Switch(flag: nil, key: "force", usage: "force reinstall")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import CommerceKit
|
||||
|
||||
struct OutdatedCommand: CommandProtocol {
|
||||
typealias Options = NoOptions<MASError>
|
||||
let verb = "outdated"
|
||||
let function = "Lists pending updates from the Mac App Store"
|
||||
public struct OutdatedCommand: CommandProtocol {
|
||||
public typealias Options = NoOptions<MASError>
|
||||
public let verb = "outdated"
|
||||
public let function = "Lists pending updates from the Mac App Store"
|
||||
|
||||
public init() {}
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
let updateController = CKUpdateController.shared()
|
||||
let updates = updateController?.availableUpdates()
|
||||
let softwareMap = CKSoftwareMap.shared()
|
||||
|
|
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import CommerceKit
|
||||
|
||||
struct ResetCommand: CommandProtocol {
|
||||
typealias Options = ResetOptions
|
||||
let verb = "reset"
|
||||
let function = "Resets the Mac App Store"
|
||||
public struct ResetCommand: CommandProtocol {
|
||||
public typealias Options = ResetOptions
|
||||
public let verb = "reset"
|
||||
public let function = "Resets the Mac App Store"
|
||||
|
||||
public init() {}
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
/*
|
||||
The "Reset Application" command in the Mac App Store debug menu performs
|
||||
the following steps
|
||||
|
@ -71,19 +73,19 @@ struct ResetCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return .success(())
|
||||
}
|
||||
}
|
||||
|
||||
struct ResetOptions: OptionsProtocol {
|
||||
public struct ResetOptions: OptionsProtocol {
|
||||
let debug: Bool
|
||||
|
||||
static func create(debug: Bool) -> ResetOptions {
|
||||
|
||||
public static func create(debug: Bool) -> ResetOptions {
|
||||
return ResetOptions(debug: debug)
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<ResetOptions, CommandantError<MASError>> {
|
||||
|
||||
public static func evaluate(_ m: CommandMode) -> Result<ResetOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Switch(flag: nil, key: "debug", usage: "Enable debug mode")
|
||||
}
|
||||
|
|
|
@ -18,12 +18,14 @@ struct ResultKeys {
|
|||
static let Price = "price"
|
||||
}
|
||||
|
||||
struct SearchCommand: CommandProtocol {
|
||||
typealias Options = SearchOptions
|
||||
let verb = "search"
|
||||
let function = "Search for apps from the Mac App Store"
|
||||
public struct SearchCommand: CommandProtocol {
|
||||
public typealias Options = SearchOptions
|
||||
public let verb = "search"
|
||||
public let function = "Search for apps from the Mac App Store"
|
||||
|
||||
public init() {}
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
|
||||
guard let searchURLString = searchURLString(options.appName),
|
||||
let searchJson = URLSession.requestSynchronousJSONWithURLString(searchURLString) as? [String: Any] else {
|
||||
|
@ -77,17 +79,17 @@ struct SearchCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
struct SearchOptions: OptionsProtocol {
|
||||
public struct SearchOptions: OptionsProtocol {
|
||||
let appName: String
|
||||
let price: Bool
|
||||
|
||||
static func create(_ appName: String) -> (_ price: Bool) -> SearchOptions {
|
||||
|
||||
public static func create(_ appName: String) -> (_ price: Bool) -> SearchOptions {
|
||||
return { price in
|
||||
SearchOptions(appName: appName, price: price)
|
||||
}
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<SearchOptions, CommandantError<MASError>> {
|
||||
|
||||
public static func evaluate(_ m: CommandMode) -> Result<SearchOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Argument(usage: "the app name to search")
|
||||
<*> m <| Option(key: "price", defaultValue: false, usage: "Show price of found apps")
|
||||
|
|
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import StoreFoundation
|
||||
|
||||
struct SignInCommand: CommandProtocol {
|
||||
typealias Options = SignInOptions
|
||||
let verb = "signin"
|
||||
let function = "Sign in to the Mac App Store"
|
||||
public struct SignInCommand: CommandProtocol {
|
||||
public typealias Options = SignInOptions
|
||||
public let verb = "signin"
|
||||
public let function = "Sign in to the Mac App Store"
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public init() {}
|
||||
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
|
||||
if #available(macOS 10.13, *) {
|
||||
return .failure(.signInDisabled)
|
||||
|
@ -44,13 +46,13 @@ struct SignInCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
struct SignInOptions: OptionsProtocol {
|
||||
public struct SignInOptions: OptionsProtocol {
|
||||
let username: String
|
||||
let password: String
|
||||
|
||||
let dialog: Bool
|
||||
|
||||
typealias ClientError = MASError
|
||||
public typealias ClientError = MASError
|
||||
|
||||
static func create(username: String) -> (_ password: String) -> (_ dialog: Bool) -> SignInOptions {
|
||||
return { password in { dialog in
|
||||
|
@ -58,7 +60,7 @@ struct SignInOptions: OptionsProtocol {
|
|||
}}
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
|
||||
public static func evaluate(_ m: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Argument(usage: "Apple ID")
|
||||
<*> m <| Argument(defaultValue: "", usage: "Password")
|
||||
|
|
|
@ -10,12 +10,14 @@ import Commandant
|
|||
import Result
|
||||
import CommerceKit
|
||||
|
||||
struct SignOutCommand: CommandProtocol {
|
||||
typealias Options = NoOptions<MASError>
|
||||
let verb = "signout"
|
||||
let function = "Sign out of the Mac App Store"
|
||||
public struct SignOutCommand: CommandProtocol {
|
||||
public typealias Options = NoOptions<MASError>
|
||||
public let verb = "signout"
|
||||
public let function = "Sign out of the Mac App Store"
|
||||
|
||||
public init() {}
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
if #available(macOS 10.13, *) {
|
||||
let accountService: ISAccountService = ISServiceProxy.genericShared().accountService
|
||||
accountService.signOut()
|
||||
|
|
|
@ -10,14 +10,16 @@ import Commandant
|
|||
import Result
|
||||
import CommerceKit
|
||||
|
||||
struct UpgradeCommand: CommandProtocol {
|
||||
typealias Options = UpgradeOptions
|
||||
let verb = "upgrade"
|
||||
let function = "Upgrade outdated apps from the Mac App Store"
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public struct UpgradeCommand: CommandProtocol {
|
||||
public typealias Options = UpgradeOptions
|
||||
public let verb = "upgrade"
|
||||
public let function = "Upgrade outdated apps from the Mac App Store"
|
||||
|
||||
public init() {}
|
||||
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
let updateController = CKUpdateController.shared()
|
||||
|
||||
|
||||
let updates: [CKUpdate]
|
||||
let apps = options.apps
|
||||
if apps.count > 0 {
|
||||
|
@ -75,14 +77,14 @@ struct UpgradeCommand: CommandProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
struct UpgradeOptions: OptionsProtocol {
|
||||
public struct UpgradeOptions: OptionsProtocol {
|
||||
let apps: [String]
|
||||
|
||||
static func create(_ apps: [String]) -> UpgradeOptions {
|
||||
return UpgradeOptions(apps: apps)
|
||||
}
|
||||
|
||||
static func evaluate(_ m: CommandMode) -> Result<UpgradeOptions, CommandantError<MASError>> {
|
||||
public static func evaluate(_ m: CommandMode) -> Result<UpgradeOptions, CommandantError<MASError>> {
|
||||
return create
|
||||
<*> m <| Argument(defaultValue: [], usage: "app(s) to upgrade")
|
||||
}
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
import Commandant
|
||||
import Result
|
||||
|
||||
struct VersionCommand: CommandProtocol {
|
||||
typealias Options = NoOptions<MASError>
|
||||
let verb = "version"
|
||||
let function = "Print version number"
|
||||
|
||||
func run(_ options: Options) -> Result<(), MASError> {
|
||||
public struct VersionCommand: CommandProtocol {
|
||||
public typealias Options = NoOptions<MASError>
|
||||
public let verb = "version"
|
||||
public let function = "Print version number"
|
||||
|
||||
public init() {}
|
||||
|
||||
public func run(_ options: Options) -> Result<(), MASError> {
|
||||
let plist = Bundle.main.infoDictionary
|
||||
if let versionString = plist?["CFBundleShortVersionString"] {
|
||||
print(versionString)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
enum MASError: Error, CustomStringConvertible {
|
||||
public enum MASError: Error, CustomStringConvertible {
|
||||
case notSignedIn
|
||||
case signInDisabled
|
||||
case signInFailed(error: NSError?)
|
||||
|
@ -22,7 +22,7 @@ enum MASError: Error, CustomStringConvertible {
|
|||
case searchFailed
|
||||
case noSearchResultsFound
|
||||
|
||||
var description: String {
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .notSignedIn:
|
||||
return "Not signed in"
|
||||
|
|
|
@ -32,7 +32,7 @@ func printWarning(_ message: String) {
|
|||
print("\(csi)4;33mWarning:\(csi)0m \(message)")
|
||||
}
|
||||
|
||||
func printError(_ message: String) {
|
||||
public func printError(_ message: String) {
|
||||
guard isatty(fileno(stdout)) != 0 else {
|
||||
print("Warning: \(message)")
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue