Skip to content

Commit

Permalink
Add select and update options to install
Browse files Browse the repository at this point in the history
  • Loading branch information
tahirmt committed Sep 20, 2022
1 parent 030ac5f commit a22f4db
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 91 deletions.
5 changes: 5 additions & 0 deletions Sources/XcodesKit/XcodeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public final class XcodeInstaller {
Current.shell.exit(0)
}
}

/// Perform the install but don't exit out but return the installed xcode version as output instead
public func installWithoutLogging(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, experimentalUnxip: Bool) -> Promise<InstalledXcode> {
self.install(installationType, dataSource: dataSource, downloader: downloader, destination: destination, attemptNumber: 0, experimentalUnxip: experimentalUnxip)
}

private func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, attemptNumber: Int, experimentalUnxip: Bool, emptyTrash: Bool, noSuperuser: Bool) -> Promise<InstalledXcode> {
return firstly { () -> Promise<(Xcode, URL)> in
Expand Down
23 changes: 14 additions & 9 deletions Sources/XcodesKit/XcodeSelect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Path
import Version
import Rainbow

public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Path) -> Promise<Void> {
public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Path, fallbackToInteractive: Bool = true) -> Promise<Void> {
firstly { () -> Promise<ProcessOutput> in
Current.shell.xcodeSelectPrintPath()
}
Expand Down Expand Up @@ -48,18 +48,23 @@ public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Pat
return Promise.value(())
}

return selectXcodeAtPath(pathToSelect)
let selectPromise = selectXcodeAtPath(pathToSelect)
.done { output in
Current.logging.log("Selected \(output.out)".green)
Current.shell.exit(0)
}
.recover { _ in
selectXcodeInteractively(currentPath: output.out, directory: directory)
.done { output in
Current.logging.log("Selected \(output.out)".green)
Current.shell.exit(0)
}
}
if fallbackToInteractive {
return selectPromise
.recover { _ in
selectXcodeInteractively(currentPath: output.out, directory: directory)
.done { output in
Current.logging.log("Selected \(output.out)".green)
Current.shell.exit(0)
}
}
} else {
return selectPromise
}
}
}
}
Expand Down
Loading

0 comments on commit a22f4db

Please sign in to comment.