Skip to content

Commit 99152cf

Browse files
committed
Improve error message when using xcode select without xcode install
1 parent aa795f8 commit 99152cf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Sources/XcodesKit/XcodeSelect.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Pat
2424

2525
let versionToSelect = pathOrVersion.isEmpty ? Version.fromXcodeVersionFile() : Version(xcodeVersion: pathOrVersion)
2626
let installedXcodes = Current.files.installedXcodes(directory)
27+
28+
if installedXcodes.isEmpty {
29+
Current.logging.log("No Xcode version installed. Please run 'xcodes install' and try again".red)
30+
Current.shell.exit(1)
31+
return Promise(error: XcodeSelectError.noInstalledXcodes)
32+
}
33+
2734
if let version = versionToSelect,
2835
let installedXcode = installedXcodes.first(withVersion: version) {
2936
let selectedInstalledXcodeVersion = installedXcodes.first { output.out.hasPrefix($0.path.string) }.map { $0.version }
@@ -153,13 +160,16 @@ public func selectXcodeAtPath(_ pathString: String) -> Promise<ProcessOutput> {
153160
public enum XcodeSelectError: LocalizedError {
154161
case invalidPath(String)
155162
case invalidIndex(min: Int, max: Int, given: String?)
163+
case noInstalledXcodes
156164

157165
public var errorDescription: String? {
158166
switch self {
159167
case .invalidPath(let pathString):
160-
return "Not a valid Xcode path: \(pathString)"
168+
"Not a valid Xcode path: \(pathString)"
161169
case .invalidIndex(let min, let max, let given):
162-
return "Not a valid number. Expecting a whole number between \(min)-\(max), but given \(given ?? "nothing")."
170+
"Not a valid number. Expecting a whole number between \(min)-\(max), but given \(given ?? "nothing")."
171+
case .noInstalledXcodes:
172+
"No Xcode version installed. Please run 'xcodes install' and try again."
163173
}
164174
}
165175
}

0 commit comments

Comments
 (0)