Skip to content

Commit

Permalink
Merge pull request #182 from tahirmt/add-select-option-to-install
Browse files Browse the repository at this point in the history
Add select option to install
  • Loading branch information
MattKiazyk authored Oct 26, 2022
2 parents 9fb3593 + 77d2e29 commit f9771ca
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 92 deletions.
6 changes: 3 additions & 3 deletions Sources/XcodesKit/XcodeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ public final class XcodeInstaller {
case aria2(Path)
}

public func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, experimentalUnxip: Bool = false, emptyTrash: Bool, noSuperuser: Bool) -> Promise<Void> {
public func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, experimentalUnxip: Bool = false, emptyTrash: Bool, noSuperuser: Bool) -> Promise<InstalledXcode> {
return firstly { () -> Promise<InstalledXcode> in
return self.install(installationType, dataSource: dataSource, downloader: downloader, destination: destination, attemptNumber: 0, experimentalUnxip: experimentalUnxip, emptyTrash: emptyTrash, noSuperuser: noSuperuser)
}
.done { xcode in
.map { xcode in
Current.logging.log("\nXcode \(xcode.version.descriptionWithoutBuildMetadata) has been installed to \(xcode.path.string)".green)
Current.shell.exit(0)
return xcode
}
}

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 f9771ca

Please sign in to comment.