Skip to content

Commit afbd797

Browse files
committed
Pull list of linux platforms out into a var.
1 parent 0cc129c commit afbd797

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ var swiftGPGKeysRefreshed = false
77
/// This implementation can be reused for any supported Linux platform.
88
/// TODO: replace dummy implementations
99
public struct Linux: Platform {
10+
let linuxPlatforms = [
11+
PlatformDefinition.ubuntu2404,
12+
PlatformDefinition.ubuntu2310,
13+
PlatformDefinition.ubuntu2204,
14+
PlatformDefinition.ubuntu2004,
15+
PlatformDefinition.ubuntu1804,
16+
PlatformDefinition.fedora39,
17+
PlatformDefinition.rhel9,
18+
PlatformDefinition.amazonlinux2,
19+
PlatformDefinition.debian12,
20+
]
21+
1022
public init() {}
1123

1224
public var appDataDirectory: URL {
@@ -473,19 +485,7 @@ public struct Linux: Platform {
473485
print("This platform could not be detected, but a toolchain for one of the supported platforms may work on it.")
474486
}
475487

476-
let linuxPlatforms = [
477-
PlatformDefinition.ubuntu2404,
478-
PlatformDefinition.ubuntu2310,
479-
PlatformDefinition.ubuntu2204,
480-
PlatformDefinition.ubuntu2004,
481-
PlatformDefinition.ubuntu1804,
482-
PlatformDefinition.fedora39,
483-
PlatformDefinition.rhel9,
484-
PlatformDefinition.amazonlinux2,
485-
PlatformDefinition.debian12,
486-
]
487-
488-
let selections = linuxPlatforms.enumerated().map { "\($0 + 1)) \($1.namePretty)" }.joined(separator: "\n")
488+
let selections = self.linuxPlatforms.enumerated().map { "\($0 + 1)) \($1.namePretty)" }.joined(separator: "\n")
489489

490490
print("""
491491
Please select the platform to use for toolchain downloads:
@@ -494,26 +494,24 @@ public struct Linux: Platform {
494494
\(selections)
495495
""")
496496

497-
let choice = SwiftlyCore.readLine(prompt: "Pick one of the available selections [0-\(linuxPlatforms.count)] ") ?? "0"
497+
let choice = SwiftlyCore.readLine(prompt: "Pick one of the available selections [0-\(self.linuxPlatforms.count)] ") ?? "0"
498498

499499
guard let choiceNum = Int(choice) else {
500500
fatalError("Installation canceled")
501501
}
502502

503-
guard choiceNum > 0 && choiceNum <= linuxPlatforms.count else {
503+
guard choiceNum > 0 && choiceNum <= self.linuxPlatforms.count else {
504504
fatalError("Installation canceled")
505505
}
506506

507-
return linuxPlatforms[choiceNum - 1]
507+
return self.linuxPlatforms[choiceNum - 1]
508508
}
509509

510510
public func detectPlatform(disableConfirmation: Bool, platform: String?) async throws -> PlatformDefinition {
511511
// We've been given a hint to use
512512
if let platform {
513-
let linuxPlatforms = [PlatformDefinition.ubuntu2404, .ubuntu2310, .ubuntu2204, .ubuntu2004, .ubuntu1804, .amazonlinux2, .rhel9, .fedora39, .debian12]
514-
515513
guard let pd = linuxPlatforms.first(where: { $0.nameFull == platform }) else {
516-
fatalError("Unrecognized platform \(platform). Recognized values: \(linuxPlatforms.map(\.nameFull).joined(separator: ", ")).")
514+
fatalError("Unrecognized platform \(platform). Recognized values: \(self.linuxPlatforms.map(\.nameFull).joined(separator: ", ")).")
517515
}
518516

519517
return pd

0 commit comments

Comments
 (0)