From d156e737d88dfde7f129a61b17228812d89203cf Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Fri, 10 Aug 2018 20:31:03 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9B=94=20Disable=20signin=20command=20on=20m?= =?UTF-8?q?acOS=2010.13=20and=20greater?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Commands/SignIn.swift | 20 ++++++++++++-------- App/MASError.swift | 26 ++++++++++++++++---------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/App/Commands/SignIn.swift b/App/Commands/SignIn.swift index 40e84e2..c71de8f 100644 --- a/App/Commands/SignIn.swift +++ b/App/Commands/SignIn.swift @@ -13,13 +13,17 @@ struct SignInCommand: CommandProtocol { typealias Options = SignInOptions let verb = "signin" let function = "Sign in to the Mac App Store" - + func run(_ options: Options) -> Result<(), MASError> { - + + if #available(macOS 10.13, *) { + return .failure(.signInDisabled) + } + guard ISStoreAccount.primaryAccount == nil else { return .failure(.alreadySignedIn) } - + do { printInfo("Signing in to Apple ID: \(options.username)") @@ -42,17 +46,17 @@ struct SignInCommand: CommandProtocol { struct SignInOptions: OptionsProtocol { let username: String let password: String - - let dialog: Bool - + + let dialog: Bool + typealias ClientError = MASError - + static func create(username: String) -> (_ password: String) -> (_ dialog: Bool) -> SignInOptions { return { password in { dialog in return SignInOptions(username: username, password: password, dialog: dialog) }} } - + static func evaluate(_ m: CommandMode) -> Result> { return create <*> m <| Argument(usage: "Apple ID") diff --git a/App/MASError.swift b/App/MASError.swift index 4eafb4a..0883a86 100644 --- a/App/MASError.swift +++ b/App/MASError.swift @@ -10,32 +10,38 @@ import Foundation enum MASError: Error, CustomStringConvertible { case notSignedIn + case signInDisabled case signInFailed(error: NSError?) case alreadySignedIn - + case purchaseFailed(error: NSError?) case downloadFailed(error: NSError?) case noDownloads case cancelled - + case searchFailed case noSearchResultsFound - + var description: String { switch self { case .notSignedIn: return "Not signed in" - + + case .signInDisabled: + return "The 'signin' command has been disabled on this macOS version. " + + "\nFor more info see: " + + "https://github.com/mas-cli/mas/issues/107" + case .signInFailed(let error): if let error = error { return "Sign in failed: \(error.localizedDescription)" } else { return "Sign in failed" } - + case .alreadySignedIn: return "Already signed in" - + case .purchaseFailed(let error): if let error = error { return "Download request failed: \(error.localizedDescription)" @@ -49,16 +55,16 @@ enum MASError: Error, CustomStringConvertible { } else { return "Download failed" } - + case .noDownloads: return "No downloads began" - + case .cancelled: return "Download cancelled" - + case .searchFailed: return "Search failed" - + case .noSearchResultsFound: return "No results found" }