Skip to content

Commit

Permalink
Merge pull request #180 from tahirmt/do-not-hard-exit-if-xcode-alread…
Browse files Browse the repository at this point in the history
…y-installed

Do not exit(1) if xcode is already installed
  • Loading branch information
MattKiazyk authored Feb 3, 2022
2 parents cc57f35 + 8261630 commit ab1c5e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
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

0 comments on commit ab1c5e4

Please sign in to comment.