Skip to content

Commit

Permalink
Improve error message when using xcode select without xcode install
Browse files Browse the repository at this point in the history
  • Loading branch information
ngimelliUW committed Mar 4, 2024
1 parent aa795f8 commit 99152cf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/XcodesKit/XcodeSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Pat

let versionToSelect = pathOrVersion.isEmpty ? Version.fromXcodeVersionFile() : Version(xcodeVersion: pathOrVersion)
let installedXcodes = Current.files.installedXcodes(directory)

if installedXcodes.isEmpty {
Current.logging.log("No Xcode version installed. Please run 'xcodes install' and try again".red)
Current.shell.exit(1)
return Promise(error: XcodeSelectError.noInstalledXcodes)
}

if let version = versionToSelect,
let installedXcode = installedXcodes.first(withVersion: version) {
let selectedInstalledXcodeVersion = installedXcodes.first { output.out.hasPrefix($0.path.string) }.map { $0.version }
Expand Down Expand Up @@ -153,13 +160,16 @@ public func selectXcodeAtPath(_ pathString: String) -> Promise<ProcessOutput> {
public enum XcodeSelectError: LocalizedError {
case invalidPath(String)
case invalidIndex(min: Int, max: Int, given: String?)
case noInstalledXcodes

public var errorDescription: String? {
switch self {
case .invalidPath(let pathString):
return "Not a valid Xcode path: \(pathString)"
"Not a valid Xcode path: \(pathString)"
case .invalidIndex(let min, let max, let given):
return "Not a valid number. Expecting a whole number between \(min)-\(max), but given \(given ?? "nothing")."
"Not a valid number. Expecting a whole number between \(min)-\(max), but given \(given ?? "nothing")."
case .noInstalledXcodes:
"No Xcode version installed. Please run 'xcodes install' and try again."
}
}
}

0 comments on commit 99152cf

Please sign in to comment.