mirror of
https://github.com/mas-cli/mas
synced 2025-02-16 12:38:30 +00:00
🔇 Add --verbose flag to outdated command
This commit is contained in:
parent
f54b1883c3
commit
610257f292
2 changed files with 27 additions and 9 deletions
|
@ -15,7 +15,7 @@ import enum Swift.Result
|
|||
/// Command which displays a list of installed apps which have available updates
|
||||
/// ready to be installed from the Mac App Store.
|
||||
public struct OutdatedCommand: CommandProtocol {
|
||||
public typealias Options = NoOptions<MASError>
|
||||
public typealias Options = OutdatedOptions
|
||||
public let verb = "outdated"
|
||||
public let function = "Lists pending updates from the Mac App Store"
|
||||
|
||||
|
@ -36,17 +36,19 @@ public struct OutdatedCommand: CommandProtocol {
|
|||
}
|
||||
|
||||
/// Runs the command.
|
||||
public func run(_: Options) -> Result<Void, MASError> {
|
||||
public func run(_ options: Options) -> Result<Void, MASError> {
|
||||
let promises = appLibrary.installedApps.map { installedApp in
|
||||
firstly {
|
||||
storeSearch.lookup(app: installedApp.itemIdentifier.intValue)
|
||||
}.done { storeApp in
|
||||
guard let storeApp = storeApp else {
|
||||
printWarning(
|
||||
"""
|
||||
Identifier \(installedApp.itemIdentifier) not found in store. \
|
||||
Was expected to identify \(installedApp.appName).
|
||||
""")
|
||||
if options.verbose {
|
||||
printWarning(
|
||||
"""
|
||||
Identifier \(installedApp.itemIdentifier) not found in store. \
|
||||
Was expected to identify \(installedApp.appName).
|
||||
""")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,3 +72,19 @@ public struct OutdatedCommand: CommandProtocol {
|
|||
}.wait()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public struct OutdatedOptions: OptionsProtocol {
|
||||
public typealias ClientError = MASError
|
||||
|
||||
let verbose: Bool
|
||||
|
||||
static func create(verbose: Bool) -> OutdatedOptions {
|
||||
OutdatedOptions(verbose: verbose)
|
||||
}
|
||||
|
||||
public static func evaluate(_ mode: CommandMode) -> Result<OutdatedOptions, CommandantError<MASError>> {
|
||||
create
|
||||
<*> mode <| Switch(flag: nil, key: "verbose", usage: "Show warnings about apps")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ public class OutdatedCommandSpec: QuickSpec {
|
|||
describe("outdated command") {
|
||||
it("displays apps with pending updates") {
|
||||
let cmd = OutdatedCommand()
|
||||
let result = cmd.run(OutdatedCommand.Options())
|
||||
let result = cmd.run(OutdatedCommand.Options(verbose: true))
|
||||
print(result)
|
||||
// expect(result).to(beSuccess())
|
||||
expect(result).to(beSuccess())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue