Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ struct Install: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

var config = try await Config.load(ctx)

Expand Down
6 changes: 5 additions & 1 deletion Sources/Swiftly/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ struct List: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

let selector = try self.toolchainSelector.map { input in
try ToolchainSelector(parsing: input)
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/Swiftly/ListAvailable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ struct ListAvailable: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

let selector = try self.toolchainSelector.map { input in
try ToolchainSelector(parsing: input)
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/Swiftly/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ struct Run: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

// Handle the specific case where help is requested of the run subcommand
if command == ["--help"] {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftly/SelfUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct SelfUpdate: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let _ = try await validateSwiftly(ctx)

let swiftlyBin = Swiftly.currentPlatform.swiftlyBinDir(ctx) / "swiftly"
guard try await fs.exists(atPath: swiftlyBin) else {
Expand Down
20 changes: 19 additions & 1 deletion Sources/Swiftly/Swiftly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension Data {
}

extension SwiftlyCommand {
public mutating func validateSwiftly(_ ctx: SwiftlyCoreContext) async throws {
public mutating func validateSwiftly(_ ctx: SwiftlyCoreContext) async throws -> () -> Void {
for requiredDir in Swiftly.requiredDirectories(ctx) {
guard try await fs.exists(atPath: requiredDir) else {
do {
Expand All @@ -107,5 +107,23 @@ extension SwiftlyCommand {

// Verify that the configuration exists and can be loaded
_ = try await Config.load(ctx)

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue(blocking): This will throw an error if there's some kind of an HTTP connection problem fetching the current swiftly release. That shouldn't abort the principal operation, such as use/install/etc.

suggestion: Change this to try? await so that the release is optional. Only if the release can be found and it is larger than the current version would trigger the message.

Copy link
Contributor Author

@louisunlimited louisunlimited Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, done.

let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version

return {
if shouldUpdateSwiftly {
let updateMessage = """
-----------------------------
A new release of swiftly is available
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This sentence needs a period at the end.

Please run `swiftly self-update` to update.
-----------------------------\n
"""

if let data = updateMessage.data(using: .utf8) {
FileHandle.standardError.write(data)
}
}
}
}
}
6 changes: 5 additions & 1 deletion Sources/Swiftly/Uninstall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ struct Uninstall: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

let startingConfig = try await Config.load(ctx)

let toolchains: [ToolchainVersion]
Expand Down
6 changes: 5 additions & 1 deletion Sources/Swiftly/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ struct Update: SwiftlyCommand {
}

public mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

var config = try await Config.load(ctx)

guard let parameters = try await self.resolveUpdateParameters(ctx, &config) else {
Expand Down
6 changes: 5 additions & 1 deletion Sources/Swiftly/Use.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ struct Use: SwiftlyCommand {
}

mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try await validateSwiftly(ctx)
let versionUpdateReminder = try await validateSwiftly(ctx)
defer {
versionUpdateReminder()
}

var config = try await Config.load(ctx)

// This is the bare use command where we print the selected toolchain version (or the path to it)
Expand Down
Loading