diff --git a/App/Commands/Account.swift b/App/Commands/Account.swift index c2d8ef7..d8d6e1a 100644 --- a/App/Commands/Account.swift +++ b/App/Commands/Account.swift @@ -10,12 +10,14 @@ import Commandant import Result import StoreFoundation -struct AccountCommand: CommandProtocol { - typealias Options = NoOptions - let verb = "account" - let function = "Prints the primary account Apple ID" +public struct AccountCommand: CommandProtocol { + public typealias Options = NoOptions + 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)) } diff --git a/App/Commands/Info.swift b/App/Commands/Info.swift index 170d698..64fdeb7 100644 --- a/App/Commands/Info.swift +++ b/App/Commands/Info.swift @@ -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> { + public static func evaluate(_ m: CommandMode) -> Result> { 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" diff --git a/App/Commands/Install.swift b/App/Commands/Install.swift index c5187a6..425dcd7 100644 --- a/App/Commands/Install.swift +++ b/App/Commands/Install.swift @@ -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> { + + public static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Argument(usage: "app ID(s) to install") <*> m <| Switch(flag: nil, key: "force", usage: "force reinstall") diff --git a/App/Commands/List.swift b/App/Commands/List.swift index 760d47a..4d5ea7a 100644 --- a/App/Commands/List.swift +++ b/App/Commands/List.swift @@ -10,12 +10,14 @@ import Commandant import Result import CommerceKit -struct ListCommand: CommandProtocol { - typealias Options = NoOptions - 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 + 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") diff --git a/App/Commands/Lucky.swift b/App/Commands/Lucky.swift index 7da584e..9b7ef20 100644 --- a/App/Commands/Lucky.swift +++ b/App/Commands/Lucky.swift @@ -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> { + + public static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Argument(usage: "the app name to install") <*> m <| Switch(flag: nil, key: "force", usage: "force reinstall") } - } diff --git a/App/Commands/Outdated.swift b/App/Commands/Outdated.swift index 6641370..c6d5564 100644 --- a/App/Commands/Outdated.swift +++ b/App/Commands/Outdated.swift @@ -10,12 +10,14 @@ import Commandant import Result import CommerceKit -struct OutdatedCommand: CommandProtocol { - typealias Options = NoOptions - let verb = "outdated" - let function = "Lists pending updates from the Mac App Store" +public struct OutdatedCommand: CommandProtocol { + public typealias Options = NoOptions + 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() diff --git a/App/Commands/Reset.swift b/App/Commands/Reset.swift index 375b61a..340879d 100644 --- a/App/Commands/Reset.swift +++ b/App/Commands/Reset.swift @@ -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> { + + public static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Switch(flag: nil, key: "debug", usage: "Enable debug mode") } diff --git a/App/Commands/Search.swift b/App/Commands/Search.swift index ed7cf19..ffafbab 100644 --- a/App/Commands/Search.swift +++ b/App/Commands/Search.swift @@ -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> { + + public static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Argument(usage: "the app name to search") <*> m <| Option(key: "price", defaultValue: false, usage: "Show price of found apps") diff --git a/App/Commands/SignIn.swift b/App/Commands/SignIn.swift index 0ddc93f..fc89f4f 100644 --- a/App/Commands/SignIn.swift +++ b/App/Commands/SignIn.swift @@ -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> { + public static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Argument(usage: "Apple ID") <*> m <| Argument(defaultValue: "", usage: "Password") diff --git a/App/Commands/SignOut.swift b/App/Commands/SignOut.swift index 30b8c41..03d5458 100644 --- a/App/Commands/SignOut.swift +++ b/App/Commands/SignOut.swift @@ -10,12 +10,14 @@ import Commandant import Result import CommerceKit -struct SignOutCommand: CommandProtocol { - typealias Options = NoOptions - let verb = "signout" - let function = "Sign out of the Mac App Store" +public struct SignOutCommand: CommandProtocol { + public typealias Options = NoOptions + 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() diff --git a/App/Commands/Upgrade.swift b/App/Commands/Upgrade.swift index 98cbe7e..bdd26ad 100644 --- a/App/Commands/Upgrade.swift +++ b/App/Commands/Upgrade.swift @@ -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> { + public static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Argument(defaultValue: [], usage: "app(s) to upgrade") } diff --git a/App/Commands/Version.swift b/App/Commands/Version.swift index 2bb168e..d3d4323 100644 --- a/App/Commands/Version.swift +++ b/App/Commands/Version.swift @@ -9,12 +9,14 @@ import Commandant import Result -struct VersionCommand: CommandProtocol { - typealias Options = NoOptions - let verb = "version" - let function = "Print version number" - - func run(_ options: Options) -> Result<(), MASError> { +public struct VersionCommand: CommandProtocol { + public typealias Options = NoOptions + 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) diff --git a/App/MASError.swift b/App/MASError.swift index 840e8c6..b2f87ee 100644 --- a/App/MASError.swift +++ b/App/MASError.swift @@ -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" diff --git a/App/Utilities.swift b/App/Utilities.swift index 799b4a1..f6c75aa 100644 --- a/App/Utilities.swift +++ b/App/Utilities.swift @@ -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