Improve unwrapping.

Cleanup code.

Partial #592

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2024-10-23 01:32:16 -04:00
parent 87aaba555d
commit 2edd21803b
No known key found for this signature in database
4 changed files with 13 additions and 8 deletions

View file

@ -47,7 +47,7 @@ extension ISStoreAccount: StoreAccount {
let password =
password.isEmpty && !systemDialog
? String(validatingUTF8: getpass("Password: "))!
? String(validatingUTF8: getpass("Password: ")) ?? ""
: password
guard !password.isEmpty || systemDialog else {

View file

@ -44,15 +44,18 @@ extension Mas {
}
url.scheme = masScheme
guard let urlString = url.string else {
printError("Unable to construct URL")
throw MASError.searchFailed
}
do {
try openCommand.run(arguments: url.string!)
try openCommand.run(arguments: urlString)
} catch {
printError("Unable to launch open command")
throw MASError.searchFailed
}
if openCommand.failed {
let reason = openCommand.process.terminationReason
printError("Open failed: (\(reason)) \(openCommand.stderr)")
printError("Open failed: (\(openCommand.process.terminationReason)) \(openCommand.stderr)")
throw MASError.searchFailed
}
} catch {

View file

@ -61,7 +61,7 @@ extension Mas {
if kill.terminationStatus != 0, debug {
let output = stderr.fileHandleForReading.readDataToEndOfFile()
printError("killall failed:\n\(String(data: output, encoding: String.Encoding.utf8)!)")
printError("killall failed:\n\(String(data: output, encoding: .utf8) ?? "Error info not available")")
}
// Wipe Download Directory

View file

@ -78,16 +78,18 @@ extension StoreSearch {
return nil
}
components.queryItems = [
var queryItems = [
URLQueryItem(name: "media", value: "software"),
URLQueryItem(name: "entity", value: entity.rawValue),
]
if let country {
components.queryItems!.append(URLQueryItem(name: "country", value: country))
queryItems.append(URLQueryItem(name: "country", value: country))
}
components.queryItems!.append(URLQueryItem(name: action.queryItemName, value: queryItemValue))
queryItems.append(URLQueryItem(name: action.queryItemName, value: queryItemValue))
components.queryItems = queryItems
return components.url
}