Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.2
18 changes: 18 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# .swiftformat
# mas-cli
#
# https://github.com/nicklockwood/SwiftFormat#config-file
#

--exclude Carthage/

# Disabled rules
--disable blankLinesAroundMark

# Enabled rules (disabled by default)
--enable trailingClosures

# Rule options
--commas inline
--importgrouping testable-top
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
brew "carthage"
brew "shellcheck"
brew "swiftlint"
brew "swiftformat"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- 🎨 SwiftFormat #215
- ⬆️ Nimble (7.3.2) #213
- ⬆️ Quick (1.3.2) #213
- ⬆️ Result (4.1.0) #213
Expand Down
2 changes: 1 addition & 1 deletion MasKit/AppStore/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func download(_ adamId: UInt64) -> MASError? {
}

guard let storeAccount = account as? ISStoreAccount
else { fatalError("Unable to cast StoreAccount to ISStoreAccount") }
else { fatalError("Unable to cast StoreAccount to ISStoreAccount") }
let purchase = SSPurchase(adamId: adamId, account: storeAccount)

var purchaseError: MASError?
Expand Down
2 changes: 1 addition & 1 deletion MasKit/AppStore/ISStoreAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
//

import StoreFoundation
import CommerceKit
import StoreFoundation

extension ISStoreAccount: StoreAccount {
static var primaryAccountIsPresentAndSignedIn: Bool {
Expand Down
8 changes: 4 additions & 4 deletions MasKit/AppStore/PurchaseDownloadObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import StoreFoundation
}
}

func downloadQueue(_ queue: CKDownloadQueue, changedWithAddition download: SSDownload) {
func downloadQueue(_: CKDownloadQueue, changedWithAddition download: SSDownload) {
guard download.metadata.itemIdentifier == purchase.itemIdentifier else {
return
}
clearLine()
printInfo("Downloading \(download.metadata.title)")
}

func downloadQueue(_ queue: CKDownloadQueue, changedWithRemoval download: SSDownload) {
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
guard download.metadata.itemIdentifier == purchase.itemIdentifier,
let status = download.status else {
let status = download.status else {
return
}

Expand Down Expand Up @@ -76,7 +76,7 @@ func progress(_ state: ProgressState) {

let completeLength = Int(state.percentComplete * Float(barLength))
var bar = ""
for index in 0..<barLength {
for index in 0 ..< barLength {
if index < completeLength {
bar += "#"
} else {
Expand Down
8 changes: 4 additions & 4 deletions MasKit/AppStore/SSPurchase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ typealias SSPurchaseCompletion =
extension SSPurchase {
convenience init(adamId: UInt64, account: ISStoreAccount) {
self.init()
self.buyParameters =
buyParameters =
"productType=C&price=0&salableAdamId=\(adamId)&pricingParameters=STDRDL&pg=default&appExtVrsId=0"
self.itemIdentifier = adamId
self.accountIdentifier = account.dsID
self.appleID = account.identifier
itemIdentifier = adamId
accountIdentifier = account.dsID
appleID = account.identifier

let downloadMetadata = SSDownloadMetadata()
downloadMetadata.kind = "software"
Expand Down
2 changes: 1 addition & 1 deletion MasKit/Commands/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct AccountCommand: CommandProtocol {
public init() {}

/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<(), MASError> {
if let account = ISStoreAccount.primaryAccount {
print(String(describing: account.identifier))
} else {
Expand Down
6 changes: 3 additions & 3 deletions MasKit/Commands/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public struct HomeCommand: CommandProtocol {
public func run(_ options: HomeOptions) -> Result<(), MASError> {
do {
guard let result = try storeSearch.lookup(app: options.appId)
else {
print("No results found")
return .failure(.noSearchResultsFound)
else {
print("No results found")
return .failure(.noSearchResultsFound)
}

do {
Expand Down
8 changes: 4 additions & 4 deletions MasKit/Commands/Info.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import Foundation
import Result

/// Displays app details. Uses the iTunes Lookup API:
/// https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/#lookup
Expand All @@ -27,9 +27,9 @@ public struct InfoCommand: CommandProtocol {
public func run(_ options: InfoOptions) -> Result<(), MASError> {
do {
guard let result = try storeSearch.lookup(app: options.appId)
else {
print("No results found")
return .failure(.noSearchResultsFound)
else {
print("No results found")
return .failure(.noSearchResultsFound)
}

print(AppInfoFormatter.format(app: result))
Expand Down
4 changes: 2 additions & 2 deletions MasKit/Commands/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result

/// Installs previously purchased apps from the Mac App Store.
public struct InstallCommand: CommandProtocol {
Expand Down Expand Up @@ -54,7 +54,7 @@ public struct InstallOptions: OptionsProtocol {

public static func create(_ appIds: [Int]) -> (_ forceInstall: Bool) -> InstallOptions {
return { forceInstall in
return InstallOptions(appIds: appIds.map {UInt64($0)}, forceInstall: forceInstall)
InstallOptions(appIds: appIds.map { UInt64($0) }, forceInstall: forceInstall)
}
}

Expand Down
2 changes: 1 addition & 1 deletion MasKit/Commands/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct ListCommand: CommandProtocol {
}

/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<(), MASError> {
let products = appLibrary.installedApps
if products.isEmpty {
print("No installed apps found")
Expand Down
4 changes: 2 additions & 2 deletions MasKit/Commands/Lucky.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result

/// Command which installs the first search result. This is handy as many MAS titles
/// can be long with embedded keywords.
Expand Down Expand Up @@ -89,7 +89,7 @@ public struct LuckyOptions: OptionsProtocol {

public static func create(_ appName: String) -> (_ forceInstall: Bool) -> LuckyOptions {
return { forceInstall in
return LuckyOptions(appName: appName, forceInstall: forceInstall)
LuckyOptions(appName: appName, forceInstall: forceInstall)
}
}

Expand Down
18 changes: 9 additions & 9 deletions MasKit/Commands/Open.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct OpenCommand: CommandProtocol {
public init(storeSearch: StoreSearch = MasStoreSearch(),
openCommand: ExternalCommand = OpenSystemCommand()) {
self.storeSearch = storeSearch
self.systemOpen = openCommand
systemOpen = openCommand
}

/// Runs the command.
Expand All @@ -40,20 +40,20 @@ public struct OpenCommand: CommandProtocol {
}

guard let appId = Int(options.appId)
else {
print("Invalid app ID")
return .failure(.noSearchResultsFound)
else {
print("Invalid app ID")
return .failure(.noSearchResultsFound)
}

guard let result = try storeSearch.lookup(app: appId)
else {
print("No results found")
return .failure(.noSearchResultsFound)
else {
print("No results found")
return .failure(.noSearchResultsFound)
}

guard var url = URLComponents(string: result.trackViewUrl)
else {
return .failure(.searchFailed)
else {
return .failure(.searchFailed)
}
url.scheme = masScheme

Expand Down
8 changes: 4 additions & 4 deletions MasKit/Commands/Outdated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result

/// Command which displays a list of installed apps which have available updates
/// ready to be installed from the Mac App Store.
Expand All @@ -27,15 +27,15 @@ public struct OutdatedCommand: CommandProtocol {
}

/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<(), MASError> {
let updateController = CKUpdateController.shared()
let updates = updateController?.availableUpdates()
for update in updates! {
if let installed = appLibrary.installedApp(forBundleId: update.bundleID) {
// Display version of installed app compared to available update.
print("""
\(update.itemIdentifier) \(update.title) (\(installed.bundleVersion) -> \(update.bundleVersion))
""")
\(update.itemIdentifier) \(update.title) (\(installed.bundleVersion) -> \(update.bundleVersion))
""")
} else {
print("\(update.itemIdentifier) \(update.title) (unknown -> \(update.bundleVersion))")
}
Expand Down
16 changes: 8 additions & 8 deletions MasKit/Commands/Reset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result

/// Kills several macOS processes as a means to reset the app store.
public struct ResetCommand: CommandProtocol {
Expand All @@ -21,22 +21,22 @@ public struct ResetCommand: CommandProtocol {
/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
/*
The "Reset Application" command in the Mac App Store debug menu performs
the following steps
The "Reset Application" command in the Mac App Store debug menu performs
the following steps

- killall Dock
- killall storeagent (storeagent no longer exists)
- rm com.apple.appstore download directory
- clear cookies (appears to be a no-op)

As storeagent no longer exists we will implement a slight variant and kill all
App Store-associated processes
As storeagent no longer exists we will implement a slight variant and kill all
App Store-associated processes
- storeaccountd
- storeassetd
- storedownloadd
- storeinstalld
- storelegacy
*/
*/

// Kill processes
let killProcs = [
Expand All @@ -60,7 +60,7 @@ public struct ResetCommand: CommandProtocol {
kill.launch()
kill.waitUntilExit()

if kill.terminationStatus != 0 && options.debug {
if kill.terminationStatus != 0, options.debug {
let output = stderr.fileHandleForReading.readDataToEndOfFile()
printInfo("killall failed:\r\n\(String(data: output, encoding: String.Encoding.utf8)!)")
}
Expand Down
6 changes: 3 additions & 3 deletions MasKit/Commands/SignIn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct SignInCommand: CommandProtocol {
printInfo("Signing in to Apple ID: \(options.username)")

let password: String = {
if options.password == "" && !options.dialog {
if options.password == "", !options.dialog {
return String(validatingUTF8: getpass("Password: "))!
}
return options.password
Expand All @@ -56,8 +56,8 @@ public struct SignInOptions: OptionsProtocol {

static func create(username: String) -> (_ password: String) -> (_ dialog: Bool) -> SignInOptions {
return { password in { dialog in
return SignInOptions(username: username, password: password, dialog: dialog)
}}
SignInOptions(username: username, password: password, dialog: dialog)
} }
}

public static func evaluate(_ mode: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
Expand Down
4 changes: 2 additions & 2 deletions MasKit/Commands/SignOut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result

public struct SignOutCommand: CommandProtocol {
public typealias Options = NoOptions<MASError>
Expand All @@ -18,7 +18,7 @@ public struct SignOutCommand: CommandProtocol {
public init() {}

/// Runs the command.
public func run(_ options: Options) -> Result<(), MASError> {
public func run(_: Options) -> Result<(), MASError> {
if #available(macOS 10.13, *) {
let accountService: ISAccountService = ISServiceProxy.genericShared().accountService
accountService.signOut()
Expand Down
4 changes: 2 additions & 2 deletions MasKit/Commands/Uninstall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result
import StoreFoundation

/// Command which uninstalls apps managed by the Mac App Store.
Expand Down Expand Up @@ -64,7 +64,7 @@ public struct UninstallOptions: OptionsProtocol {

static func create(_ appId: Int) -> (_ dryRun: Bool) -> UninstallOptions {
return { dryRun in
return UninstallOptions(appId: appId, dryRun: dryRun)
UninstallOptions(appId: appId, dryRun: dryRun)
}
}

Expand Down
2 changes: 1 addition & 1 deletion MasKit/Commands/Upgrade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

import Commandant
import Result
import CommerceKit
import Result

/// Command which upgrades apps with new versions available in the Mac App Store.
public struct UpgradeCommand: CommandProtocol {
Expand Down
8 changes: 4 additions & 4 deletions MasKit/Commands/Vendor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public struct VendorCommand: CommandProtocol {
public func run(_ options: VendorOptions) -> Result<(), MASError> {
do {
guard let result = try storeSearch.lookup(app: options.appId)
else {
print("No results found")
return .failure(.noSearchResultsFound)
else {
print("No results found")
return .failure(.noSearchResultsFound)
}

guard let vendorWebsite = result.sellerUrl
else { throw MASError.noVendorWebsite }
else { throw MASError.noVendorWebsite }

do {
try openCommand.run(arguments: vendorWebsite)
Expand Down
Loading