Skip to content

Commit 8b9d433

Browse files
committed
Make version field in config mandatory and remove fallback logic
This commit aligns with the decision to drop support for configurations without a version field (pre-0.3.0). The `version` property in `Config` is now non-optional and must be explicitly set at creation. - Removed the fallback assignment to "0.3.0" - Updated all code to require and use non-optional `version` - Adjusted the config initializer to take `version` as a parameter - Simplified conditional checks and eliminated `.version?` This ensures that swiftly no longer silently accepts or upgrades legacy configurations without an explicit version.
1 parent fcbe184 commit 8b9d433

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

Sources/Swiftly/Config.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ public struct Config: Codable, Equatable, Sendable {
99
public var inUse: ToolchainVersion?
1010
public var installedToolchains: Set<ToolchainVersion>
1111
public var platform: PlatformDefinition
12-
public var version: SwiftlyVersion?
12+
public var version: SwiftlyVersion
1313

14-
init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition) {
14+
init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition, version: SwiftlyVersion) {
1515
self.inUse = inUse
1616
self.installedToolchains = installedToolchains
1717
self.platform = platform
18+
self.version = version
1819
}
1920

2021
private static func makeEncoder() -> JSONEncoder {
@@ -28,12 +29,8 @@ public struct Config: Codable, Equatable, Sendable {
2829
do {
2930
let configFile = Swiftly.currentPlatform.swiftlyConfigFile(ctx)
3031
let data = try await fs.cat(atPath: configFile)
31-
var config = try JSONDecoder().decode(Config.self, from: data)
32-
if config.version == nil {
33-
// Assume that the version of swiftly is 0.3.0 because that is the last
34-
// unversioned release.
35-
config.version = SwiftlyCore.version
36-
}
32+
let config = try JSONDecoder().decode(Config.self, from: data)
33+
3734
return config
3835
} catch {
3936
let msg = """

Sources/Swiftly/Init.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Init: SwiftlyCommand {
4848
(
4949
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0, suffix: "dev") ||
5050
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0) ||
51-
(config.version?.major == 1 && config.version?.minor == 0)
51+
(config.version.major == 1 && config.version.minor == 0)
5252
)
5353
{
5454
// This is a simple upgrade from the 0.4.0 pre-releases, or 1.x
@@ -178,9 +178,8 @@ struct Init: SwiftlyCommand {
178178
// Force the configuration to be present. Generate it if it doesn't already exist or overwrite is set
179179
if overwrite || config == nil {
180180
let pd = try await Swiftly.currentPlatform.detectPlatform(ctx, disableConfirmation: assumeYes, platform: platform)
181-
var c = Config(inUse: nil, installedToolchains: [], platform: pd)
182-
// Stamp the current version of swiftly on this config
183-
c.version = SwiftlyCore.version
181+
let c = Config(inUse: nil, installedToolchains: [], platform: pd, version: SwiftlyCore.version)
182+
184183
try c.save(ctx)
185184
config = c
186185
}

0 commit comments

Comments
 (0)