forked from mas-cli/mas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutdated.swift
More file actions
59 lines (54 loc) · 1.44 KB
/
Copy pathOutdated.swift
File metadata and controls
59 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Outdated.swift
// mas
//
// Created by Andrew Naylor on 2015-08-21.
// Copyright © 2015 Andrew Naylor. All rights reserved.
//
internal import ArgumentParser
extension MAS {
/// Command which displays a list of installed apps which have available updates
/// ready to be installed from the Mac App Store.
struct Outdated: AsyncParsableCommand {
static let configuration = CommandConfiguration(
abstract: "List pending app updates from the Mac App Store"
)
@Flag(help: "Display warnings about apps unknown to the Mac App Store")
var verbose = false
/// Runs the command.
func run() async throws {
try await run(installedApps: await installedApps, searcher: ITunesSearchAppStoreSearcher())
}
func run(installedApps: [InstalledApp], searcher: AppStoreSearcher) async throws {
for installedApp in installedApps {
do {
let storeApp = try await searcher.lookup(appID: installedApp.id)
if installedApp.isOutdated(comparedTo: storeApp) {
printInfo(
installedApp.id,
" ",
installedApp.name,
" (",
installedApp.version,
" -> ",
storeApp.version,
")",
separator: ""
)
}
} catch let MASError.unknownAppID(unknownAppID) {
if verbose {
printWarning(
"Identifier ",
unknownAppID,
" not found in store. Was expected to identify ",
installedApp.name,
".",
separator: ""
)
}
}
}
}
}
}