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
30 changes: 30 additions & 0 deletions Sources/xcodes/ParsableArguments+InstallError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ArgumentParser
import Foundation
import LegibleError
import PromiseKit
import XcodesKit
import Rainbow

extension ParsableArguments {
static func processDownloadOrInstall(error: Error) -> Never {
var exitCode: ExitCode = .failure
switch error {
case Process.PMKError.execution(let process, let standardOutput, let standardError):
Current.logging.log("""
Failed executing: `\(process)` (\(process.terminationStatus))
\([standardOutput, standardError].compactMap { $0 }.joined(separator: "\n"))
""".red)
case let error as XcodeInstaller.Error:
if case .versionAlreadyInstalled = error {
Current.logging.log(error.legibleLocalizedDescription.green)
exitCode = .success
} else {
Current.logging.log(error.legibleLocalizedDescription.red)
}
default:
Current.logging.log(error.legibleLocalizedDescription.red)
}

Self.exit(withError: exitCode)
}
}
24 changes: 2 additions & 22 deletions Sources/xcodes/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,7 @@ struct Xcodes: ParsableCommand {

installer.download(installation, dataSource: globalDataSource.dataSource, downloader: downloader, destinationDirectory: destination)
.catch { error in
switch error {
case Process.PMKError.execution(let process, let standardOutput, let standardError):
Current.logging.log("""
Failed executing: `\(process)` (\(process.terminationStatus))
\([standardOutput, standardError].compactMap { $0 }.joined(separator: "\n"))
""".red)
default:
Current.logging.log(error.legibleLocalizedDescription.red)
}

Install.exit(withError: ExitCode.failure)
Install.processDownloadOrInstall(error: error)
}

RunLoop.current.run()
Expand Down Expand Up @@ -231,17 +221,7 @@ struct Xcodes: ParsableCommand {
installer.install(installation, dataSource: globalDataSource.dataSource, downloader: downloader, destination: destination)
.done { Install.exit() }
.catch { error in
switch error {
case Process.PMKError.execution(let process, let standardOutput, let standardError):
Current.logging.log("""
Failed executing: `\(process)` (\(process.terminationStatus))
\([standardOutput, standardError].compactMap { $0 }.joined(separator: "\n"))
""".red)
default:
Current.logging.log(error.legibleLocalizedDescription.red)
}

Install.exit(withError: ExitCode.failure)
Install.processDownloadOrInstall(error: error)
}

RunLoop.current.run()
Expand Down