Skip to content

Commit ab1c5e4

Browse files
authored
Merge pull request #180 from tahirmt/do-not-hard-exit-if-xcode-already-installed
Do not exit(1) if xcode is already installed
2 parents cc57f35 + 8261630 commit ab1c5e4

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import ArgumentParser
2+
import Foundation
3+
import LegibleError
4+
import PromiseKit
5+
import XcodesKit
6+
import Rainbow
7+
8+
extension ParsableArguments {
9+
static func processDownloadOrInstall(error: Error) -> Never {
10+
var exitCode: ExitCode = .failure
11+
switch error {
12+
case Process.PMKError.execution(let process, let standardOutput, let standardError):
13+
Current.logging.log("""
14+
Failed executing: `\(process)` (\(process.terminationStatus))
15+
\([standardOutput, standardError].compactMap { $0 }.joined(separator: "\n"))
16+
""".red)
17+
case let error as XcodeInstaller.Error:
18+
if case .versionAlreadyInstalled = error {
19+
Current.logging.log(error.legibleLocalizedDescription.green)
20+
exitCode = .success
21+
} else {
22+
Current.logging.log(error.legibleLocalizedDescription.red)
23+
}
24+
default:
25+
Current.logging.log(error.legibleLocalizedDescription.red)
26+
}
27+
28+
Self.exit(withError: exitCode)
29+
}
30+
}

Sources/xcodes/main.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,7 @@ struct Xcodes: ParsableCommand {
138138

139139
installer.download(installation, dataSource: globalDataSource.dataSource, downloader: downloader, destinationDirectory: destination)
140140
.catch { error in
141-
switch error {
142-
case Process.PMKError.execution(let process, let standardOutput, let standardError):
143-
Current.logging.log("""
144-
Failed executing: `\(process)` (\(process.terminationStatus))
145-
\([standardOutput, standardError].compactMap { $0 }.joined(separator: "\n"))
146-
""".red)
147-
default:
148-
Current.logging.log(error.legibleLocalizedDescription.red)
149-
}
150-
151-
Install.exit(withError: ExitCode.failure)
141+
Install.processDownloadOrInstall(error: error)
152142
}
153143

154144
RunLoop.current.run()
@@ -231,17 +221,7 @@ struct Xcodes: ParsableCommand {
231221
installer.install(installation, dataSource: globalDataSource.dataSource, downloader: downloader, destination: destination)
232222
.done { Install.exit() }
233223
.catch { error in
234-
switch error {
235-
case Process.PMKError.execution(let process, let standardOutput, let standardError):
236-
Current.logging.log("""
237-
Failed executing: `\(process)` (\(process.terminationStatus))
238-
\([standardOutput, standardError].compactMap { $0 }.joined(separator: "\n"))
239-
""".red)
240-
default:
241-
Current.logging.log(error.legibleLocalizedDescription.red)
242-
}
243-
244-
Install.exit(withError: ExitCode.failure)
224+
Install.processDownloadOrInstall(error: error)
245225
}
246226

247227
RunLoop.current.run()

0 commit comments

Comments
 (0)