Skip to content
Merged
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
23 changes: 20 additions & 3 deletions Sources/XcodesKit/XcodeSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,33 @@ public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Pat
}
}

let installedXcodes = Current.files.installedXcodes(directory)
if let version = Version(xcodeVersion: pathOrVersion),
let installedXcode = Current.files.installedXcodes(directory).first(withVersion: version) {
let installedXcode = installedXcodes.first(withVersion: version) {
let selectedInstalledXcodeVersion = installedXcodes.first { output.out.hasPrefix($0.path.string) }.map { $0.version }
if installedXcode.version == selectedInstalledXcodeVersion {
Current.logging.log("Xcode \(version) is already selected".green)
Current.shell.exit(0)
return Promise.value(())
}

return selectXcodeAtPath(installedXcode.path.string)
.done { output in
Current.logging.log("Selected \(output.out)".green)
Current.shell.exit(0)
}
}
else {
return selectXcodeAtPath(pathOrVersion)
let pathToSelect = pathOrVersion.trimmingCharacters(in: .whitespacesAndNewlines)
let currentPath = output.out.trimmingCharacters(in: .whitespacesAndNewlines)

if pathToSelect == currentPath {
Current.logging.log("Xcode at path \(pathOrVersion) is already selected".green)
Current.shell.exit(0)
return Promise.value(())
}

return selectXcodeAtPath(pathToSelect)
.done { output in
Current.logging.log("Selected \(output.out)".green)
Current.shell.exit(0)
Expand Down Expand Up @@ -94,7 +111,7 @@ public func chooseFromInstalledXcodesInteractively(currentPath: String, director
return Promise(error: error)
}

return Promise.value(sortedInstalledXcodes[selectionNumber - 1])
return Promise.value(sortedInstalledXcodes[selectionNumber - 1])
}

public func selectXcodeInteractively(currentPath: String, directory: Path) -> Promise<ProcessOutput> {
Expand Down