mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 03:23:08 +00:00
commit
4c044d8b64
12 changed files with 35 additions and 19 deletions
|
@ -78,8 +78,8 @@
|
|||
"repositoryURL": "https://github.com/apple/swift-syntax",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "04d4497be6b88e524a71778d828790e9589ae1c4",
|
||||
"version": "0.50700.0"
|
||||
"revision": "72d3da66b085c2299dd287c2be3b92b5ebd226de",
|
||||
"version": "0.50700.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ public struct AccountCommand: CommandProtocol {
|
|||
if let account = ISStoreAccount.primaryAccount {
|
||||
print(String(describing: account.identifier))
|
||||
} else {
|
||||
print("Not signed in")
|
||||
printError("Not signed in")
|
||||
return .failure(.notSignedIn)
|
||||
}
|
||||
return .success(())
|
||||
|
|
|
@ -39,7 +39,6 @@ public struct HomeCommand: CommandProtocol {
|
|||
public func run(_ options: HomeOptions) -> Result<Void, MASError> {
|
||||
do {
|
||||
guard let result = try storeSearch.lookup(app: options.appId).wait() else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ public struct InfoCommand: CommandProtocol {
|
|||
public func run(_ options: InfoOptions) -> Result<Void, MASError> {
|
||||
do {
|
||||
guard let result = try storeSearch.lookup(app: options.appId).wait() else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public struct ListCommand: CommandProtocol {
|
|||
public func run(_: Options) -> Result<Void, MASError> {
|
||||
let products = appLibrary.installedApps
|
||||
if products.isEmpty {
|
||||
print("No installed apps found")
|
||||
printError("No installed apps found")
|
||||
return .success(())
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public struct LuckyCommand: CommandProtocol {
|
|||
do {
|
||||
let results = try storeSearch.search(for: options.appName).wait()
|
||||
guard let result = results.first else {
|
||||
print("No results found")
|
||||
printError("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ public struct OpenCommand: CommandProtocol {
|
|||
|
||||
guard let result = try storeSearch.lookup(app: appId).wait()
|
||||
else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,18 @@ 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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ public struct SearchCommand: CommandProtocol {
|
|||
do {
|
||||
let results = try storeSearch.search(for: options.appName).wait()
|
||||
if results.isEmpty {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ public struct VendorCommand: CommandProtocol {
|
|||
do {
|
||||
guard let result = try storeSearch.lookup(app: options.appId).wait()
|
||||
else {
|
||||
print("No results found")
|
||||
return .failure(.noSearchResultsFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ extension FileHandle: TextOutputStream {
|
|||
}
|
||||
}
|
||||
|
||||
/// Prints a message to stdout prefixed with a blue arrow.
|
||||
func printInfo(_ message: String) {
|
||||
guard isatty(fileno(stdout)) != 0 else {
|
||||
print("==> \(message)")
|
||||
|
@ -89,6 +90,7 @@ func printInfo(_ message: String) {
|
|||
print("\(csi)1;34m==>\(csi)0m \(csi)1m\(message)\(csi)0m")
|
||||
}
|
||||
|
||||
/// Prints a message to stderr prefixed with "Warning:" underlined in yellow.
|
||||
public func printWarning(_ message: String) {
|
||||
guard isatty(fileno(stderr)) != 0 else {
|
||||
print("Warning: \(message)", to: &standardError)
|
||||
|
@ -99,6 +101,7 @@ public func printWarning(_ message: String) {
|
|||
print("\(csi)4;33mWarning:\(csi)0m \(message)", to: &standardError)
|
||||
}
|
||||
|
||||
/// Prints a message to stderr prefixed with "Error:" underlined in red.
|
||||
public func printError(_ message: String) {
|
||||
guard isatty(fileno(stderr)) != 0 else {
|
||||
print("Error: \(message)", to: &standardError)
|
||||
|
@ -109,6 +112,7 @@ public func printError(_ message: String) {
|
|||
print("\(csi)4;31mError:\(csi)0m \(message)", to: &standardError)
|
||||
}
|
||||
|
||||
/// Flushes stdout.
|
||||
func clearLine() {
|
||||
guard isatty(fileno(stdout)) != 0 else {
|
||||
return
|
||||
|
|
|
@ -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…
Reference in a new issue