Skip to content

Commit 1f8dc6c

Browse files
committed
Expose architecture filters in CLI lists
Uses shared XcodesKit filtering support adapted from #470 by wmehanna.
1 parent a35fae4 commit 1f8dc6c

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

Sources/XcodesKit/RuntimeInstaller.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class RuntimeInstaller: Sendable {
1616
self.sessionService = sessionService
1717
}
1818

19-
public func printAvailableRuntimes(includeBetas: Bool) async throws {
19+
public func printAvailableRuntimes(includeBetas: Bool, architectures: [Architecture] = []) async throws {
2020
let presentationService = RuntimeListPresentationService()
2121
let downloadableRuntimeList = try await runtimeList.updateDownloadableRuntimeList()
2222
let installedRuntimes = try await runtimeList.installedRuntimes()
@@ -25,7 +25,8 @@ public final class RuntimeInstaller: Sendable {
2525
downloadableRuntimes: downloadableRuntimeList.runtimes,
2626
installedRuntimes: installedRuntimes,
2727
includeBetas: includeBetas,
28-
sdkToSeedMappings: downloadableRuntimeList.sdkToSeedMappings
28+
sdkToSeedMappings: downloadableRuntimeList.sdkToSeedMappings,
29+
architectures: architectures
2930
) {
3031
Current.logging.log("-- \(platform.shortName) --")
3132
runtimes.forEach { Current.logging.log(presentationService.line(for: $0)) }

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,21 +491,22 @@ public final class XcodeInstaller: Sendable {
491491
return try await xcodeList.updateAvailableXcodes(dataSource: dataSource)
492492
}
493493

494-
public func updateAndPrint(dataSource: DataSource, directory: Path) async throws {
494+
public func updateAndPrint(dataSource: DataSource, directory: Path, architectures: [Architecture] = []) async throws {
495495
let xcodes = try await update(dataSource: dataSource)
496-
try await printAvailableXcodes(xcodes, installed: Current.files.installedXcodes(directory), dataSource: dataSource)
496+
try await printAvailableXcodes(xcodes, installed: Current.files.installedXcodes(directory), dataSource: dataSource, architectures: architectures)
497497
Current.shell.exit(0)
498498
}
499499

500-
public func printAvailableXcodes(_ xcodes: [Xcode], installed installedXcodes: [InstalledXcode], dataSource: DataSource = .xcodeReleases) async throws {
500+
public func printAvailableXcodes(_ xcodes: [Xcode], installed installedXcodes: [InstalledXcode], dataSource: DataSource = .xcodeReleases, architectures: [Architecture] = []) async throws {
501501
let output = try await Current.shell.xcodeSelectPrintPath()
502502

503503
XcodeListPresentationService()
504504
.availableRows(
505505
availableXcodes: xcodes,
506506
installedXcodes: installedXcodes,
507507
selectedXcodePath: output.out,
508-
dataSource: dataSource
508+
dataSource: dataSource,
509+
architectures: architectures
509510
)
510511
.forEach { row in
511512
var output = row.versionDescription

Sources/xcodes/App.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct GlobalColorOption: ParsableArguments {
5555
var color: Bool = true
5656
}
5757

58+
extension Architecture: @retroactive ExpressibleByArgument {}
59+
5860
@main
5961
struct Xcodes: AsyncParsableCommand {
6062
static let configuration = CommandConfiguration(
@@ -361,6 +363,9 @@ struct Xcodes: AsyncParsableCommand {
361363
abstract: "List all versions of Xcode that are available to install"
362364
)
363365

366+
@Option(help: "Only list Xcodes that support the specified architecture: arm64 or x86_64. Can be used multiple times.")
367+
var architecture: [Architecture] = []
368+
364369
@OptionGroup
365370
var globalDirectory: GlobalDirectoryOption
366371

@@ -378,10 +383,10 @@ struct Xcodes: AsyncParsableCommand {
378383

379384
do {
380385
if services.xcodeList.shouldUpdateBeforeListingVersions {
381-
try await services.xcodeInstaller.updateAndPrint(dataSource: globalDataSource.dataSource, directory: directory)
386+
try await services.xcodeInstaller.updateAndPrint(dataSource: globalDataSource.dataSource, directory: directory, architectures: architecture)
382387
}
383388
else {
384-
try await services.xcodeInstaller.printAvailableXcodes(services.xcodeList.availableXcodes, installed: Current.files.installedXcodes(directory))
389+
try await services.xcodeInstaller.printAvailableXcodes(services.xcodeList.availableXcodes, installed: Current.files.installedXcodes(directory), architectures: architecture)
385390
}
386391
List.exit()
387392
} catch {
@@ -399,9 +404,12 @@ struct Xcodes: AsyncParsableCommand {
399404
@Flag(help: "Include beta runtimes available to install")
400405
var includeBetas: Bool = false
401406

407+
@Option(help: "Only list runtimes that support the specified architecture: arm64 or x86_64. Can be used multiple times.")
408+
var architecture: [Architecture] = []
409+
402410
func run() async throws {
403411
let services = Xcodes.makeServices()
404-
try await services.runtimeInstaller.printAvailableRuntimes(includeBetas: includeBetas)
412+
try await services.runtimeInstaller.printAvailableRuntimes(includeBetas: includeBetas, architectures: architecture)
405413
}
406414

407415
struct Install: AsyncParsableCommand {

0 commit comments

Comments
 (0)