mirror of
https://github.com/mas-cli/mas
synced 2025-02-16 20:48:30 +00:00
Guard against not being signed in with an error
This commit is contained in:
parent
b3c64f7514
commit
83291f2fc6
5 changed files with 52 additions and 20 deletions
|
@ -24,7 +24,7 @@
|
||||||
ED0F23891B87543D00AE40CD /* DownloadQueueObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F23881B87543D00AE40CD /* DownloadQueueObserver.swift */; };
|
ED0F23891B87543D00AE40CD /* DownloadQueueObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F23881B87543D00AE40CD /* DownloadQueueObserver.swift */; };
|
||||||
ED0F238B1B87569C00AE40CD /* Downloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238A1B87569C00AE40CD /* Downloader.swift */; };
|
ED0F238B1B87569C00AE40CD /* Downloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238A1B87569C00AE40CD /* Downloader.swift */; };
|
||||||
ED0F238D1B8756E600AE40CD /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238C1B8756E600AE40CD /* Error.swift */; };
|
ED0F238D1B8756E600AE40CD /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238C1B8756E600AE40CD /* Error.swift */; };
|
||||||
ED0F23901B87A56F00AE40CD /* StoreAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238F1B87A56F00AE40CD /* StoreAccount.swift */; };
|
ED0F23901B87A56F00AE40CD /* ISStoreAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238F1B87A56F00AE40CD /* ISStoreAccount.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 */; };
|
||||||
F5F01044EC3065C6EBAB95D7 /* BoxType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0E87CFA5E6371893D5B1807 /* BoxType.swift */; };
|
F5F01044EC3065C6EBAB95D7 /* BoxType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0E87CFA5E6371893D5B1807 /* BoxType.swift */; };
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
ED0F23881B87543D00AE40CD /* DownloadQueueObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadQueueObserver.swift; sourceTree = "<group>"; };
|
ED0F23881B87543D00AE40CD /* DownloadQueueObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadQueueObserver.swift; sourceTree = "<group>"; };
|
||||||
ED0F238A1B87569C00AE40CD /* Downloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Downloader.swift; sourceTree = "<group>"; };
|
ED0F238A1B87569C00AE40CD /* Downloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Downloader.swift; sourceTree = "<group>"; };
|
||||||
ED0F238C1B8756E600AE40CD /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
|
ED0F238C1B8756E600AE40CD /* Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Error.swift; sourceTree = "<group>"; };
|
||||||
ED0F238F1B87A56F00AE40CD /* StoreAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreAccount.swift; sourceTree = "<group>"; };
|
ED0F238F1B87A56F00AE40CD /* ISStoreAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ISStoreAccount.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>"; };
|
||||||
EDEAA0C31B51CEE400F2FC3F /* CDStructures.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDStructures.h; sourceTree = "<group>"; };
|
EDEAA0C31B51CEE400F2FC3F /* CDStructures.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDStructures.h; sourceTree = "<group>"; };
|
||||||
EDEAA0C41B51CEE400F2FC3F /* CKBook.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CKBook.h; sourceTree = "<group>"; };
|
EDEAA0C41B51CEE400F2FC3F /* CKBook.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CKBook.h; sourceTree = "<group>"; };
|
||||||
|
@ -352,7 +352,7 @@
|
||||||
children = (
|
children = (
|
||||||
ED0F238A1B87569C00AE40CD /* Downloader.swift */,
|
ED0F238A1B87569C00AE40CD /* Downloader.swift */,
|
||||||
ED0F23881B87543D00AE40CD /* DownloadQueueObserver.swift */,
|
ED0F23881B87543D00AE40CD /* DownloadQueueObserver.swift */,
|
||||||
ED0F238F1B87A56F00AE40CD /* StoreAccount.swift */,
|
ED0F238F1B87A56F00AE40CD /* ISStoreAccount.swift */,
|
||||||
);
|
);
|
||||||
path = AppStore;
|
path = AppStore;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -642,13 +642,13 @@
|
||||||
B80C5DDD38A8F7EB6F320697 /* Errors.swift in Sources */,
|
B80C5DDD38A8F7EB6F320697 /* Errors.swift in Sources */,
|
||||||
5918483F96256CDAC88FF450 /* HelpCommand.swift in Sources */,
|
5918483F96256CDAC88FF450 /* HelpCommand.swift in Sources */,
|
||||||
ED0F237F1B87522400AE40CD /* Install.swift in Sources */,
|
ED0F237F1B87522400AE40CD /* Install.swift in Sources */,
|
||||||
|
ED0F23901B87A56F00AE40CD /* ISStoreAccount.swift in Sources */,
|
||||||
ED0F23831B87533A00AE40CD /* ListInstalled.swift in Sources */,
|
ED0F23831B87533A00AE40CD /* ListInstalled.swift in Sources */,
|
||||||
ED0F23851B87536A00AE40CD /* ListUpdates.swift in Sources */,
|
ED0F23851B87536A00AE40CD /* ListUpdates.swift in Sources */,
|
||||||
ED031A7C1B5127C00097692E /* main.swift in Sources */,
|
ED031A7C1B5127C00097692E /* main.swift in Sources */,
|
||||||
DE39BCA91D1BC3D876711677 /* MutableBox.swift in Sources */,
|
DE39BCA91D1BC3D876711677 /* MutableBox.swift in Sources */,
|
||||||
92828DCD99CED47F54242776 /* Option.swift in Sources */,
|
92828DCD99CED47F54242776 /* Option.swift in Sources */,
|
||||||
1CC607DA6B900AA3FEC3F6D8 /* Result.swift in Sources */,
|
1CC607DA6B900AA3FEC3F6D8 /* Result.swift in Sources */,
|
||||||
ED0F23901B87A56F00AE40CD /* StoreAccount.swift in Sources */,
|
|
||||||
7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */,
|
7858BCFB4D5A4251DE998CE4 /* Switch.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
|
17
mas-cli/AppStore/ISStoreAccount.swift
Normal file
17
mas-cli/AppStore/ISStoreAccount.swift
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
// ISStoreAccount.swift
|
||||||
|
// mas-cli
|
||||||
|
//
|
||||||
|
// Created by Andrew Naylor on 22/08/2015.
|
||||||
|
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
extension ISStoreAccount {
|
||||||
|
static var primaryAccountIsPresentAndSignedIn: Bool {
|
||||||
|
return CKAccountStore.sharedAccountStore().primaryAccountIsPresentAndSignedIn
|
||||||
|
}
|
||||||
|
|
||||||
|
static var primaryAccount: ISStoreAccount? {
|
||||||
|
return CKAccountStore.sharedAccountStore().primaryAccount
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
//
|
|
||||||
// Account.swift
|
|
||||||
// mas-cli
|
|
||||||
//
|
|
||||||
// Created by Andrew Naylor on 22/08/2015.
|
|
||||||
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
func primaryAccount() -> ISStoreAccount {
|
|
||||||
let accountController = CKAccountStore.sharedAccountStore()
|
|
||||||
return accountController.primaryAccount
|
|
||||||
}
|
|
|
@ -13,7 +13,13 @@ struct AccountCommand: CommandType {
|
||||||
func run(mode: CommandMode) -> Result<(), CommandantError<MASError>> {
|
func run(mode: CommandMode) -> Result<(), CommandantError<MASError>> {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .Arguments:
|
case .Arguments:
|
||||||
print(primaryAccount().identifier)
|
if let account = ISStoreAccount.primaryAccount {
|
||||||
|
println(account.identifier)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println("Not signed in")
|
||||||
|
exit(MASErrorCode.NotSignedIn.exitCode)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,30 @@
|
||||||
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
|
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
public enum MASError: Equatable {
|
public let MASErrorDomain: String = "MASErrorDomain"
|
||||||
public var description: String {
|
|
||||||
return ""
|
private let MASErrorSource: String = "MASErrorSource"
|
||||||
|
|
||||||
|
public enum MASErrorCode: Int {
|
||||||
|
case NoError
|
||||||
|
case NotSignedIn
|
||||||
|
|
||||||
|
var exitCode: Int32 {
|
||||||
|
return Int32(self.rawValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MASError: NSError {
|
||||||
|
var masCode: MASErrorCode? {
|
||||||
|
return MASErrorCode(rawValue: code)
|
||||||
|
}
|
||||||
|
|
||||||
|
convenience init(code: MASErrorCode, sourceError: NSError? = nil) {
|
||||||
|
var userInfo: [NSObject: AnyObject] = [:]
|
||||||
|
if let error = sourceError {
|
||||||
|
userInfo[MASErrorSource] = error
|
||||||
|
}
|
||||||
|
self.init(domain: MASErrorDomain, code: code.rawValue, userInfo: userInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue