Skip to content

Commit f9771ca

Browse files
authored
Merge pull request #182 from tahirmt/add-select-option-to-install
Add select option to install
2 parents 9fb3593 + 77d2e29 commit f9771ca

File tree

3 files changed

+141
-92
lines changed

3 files changed

+141
-92
lines changed

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ public final class XcodeInstaller {
166166
case aria2(Path)
167167
}
168168

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

Sources/XcodesKit/XcodeSelect.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Path
44
import Version
55
import Rainbow
66

7-
public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Path) -> Promise<Void> {
7+
public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Path, fallbackToInteractive: Bool = true) -> Promise<Void> {
88
firstly { () -> Promise<ProcessOutput> in
99
Current.shell.xcodeSelectPrintPath()
1010
}
@@ -48,18 +48,23 @@ public func selectXcode(shouldPrint: Bool, pathOrVersion: String, directory: Pat
4848
return Promise.value(())
4949
}
5050

51-
return selectXcodeAtPath(pathToSelect)
51+
let selectPromise = selectXcodeAtPath(pathToSelect)
5252
.done { output in
5353
Current.logging.log("Selected \(output.out)".green)
5454
Current.shell.exit(0)
5555
}
56-
.recover { _ in
57-
selectXcodeInteractively(currentPath: output.out, directory: directory)
58-
.done { output in
59-
Current.logging.log("Selected \(output.out)".green)
60-
Current.shell.exit(0)
61-
}
62-
}
56+
if fallbackToInteractive {
57+
return selectPromise
58+
.recover { _ in
59+
selectXcodeInteractively(currentPath: output.out, directory: directory)
60+
.done { output in
61+
Current.logging.log("Selected \(output.out)".green)
62+
Current.shell.exit(0)
63+
}
64+
}
65+
} else {
66+
return selectPromise
67+
}
6368
}
6469
}
6570
}

0 commit comments

Comments
 (0)