Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ struct Install: SwiftlyCommand {
mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try validateSwiftly(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.

question: can we put this code in validateSwiftly() as a kind of validation check? I think that it might make sense to have it there.

Copy link
Member

Choose a reason for hiding this comment

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

I see that one problem is with the defer block. Perhaps the validate function can return a function that should be deferred by the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, this would also make all commands that does validateSwiftly(ctx) do version checks. Which includes self-update , for now I have discarded the returned func for self-update as we don't need checks before the command that actually updates itself.

let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("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.

suggestion: Print these messages to stderr so that it doesn't interfere with other tools that might be parsing stdout. It also has the benefit of being able to quieted at the shell if a user wants using redirects like this: swiftly install 2>/dev/null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a predefined way of doing prints to stderr? Currently I'm using fileHandler to route to stderr, I see that print() depends on the context and would it be better modifying outputHandler in the context to be stderr and then change it back to being stdout?

Copy link
Member

Choose a reason for hiding this comment

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

I think that it's ok in this context to print directly to stderr outside of the ctx.print(). The context is there for the purpose of mocks during testing, and I don't think that this feature warrants testing of what it prints to stderr.

In terms of how to print to stderr, I think that these FileHandle API's in Foundation could work for this:
https://developer.apple.com/documentation/foundation/filehandle/standarderror
https://developer.apple.com/documentation/foundation/filehandle/write(contentsof:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nice, that's exactly what I used for printing out to stderr, I'll mark this pr for review then, thanks!

ctx.print("Please run `swiftly self-update` to update.")
}
}

var config = try Config.load(ctx)

var selector: ToolchainSelector
Expand Down
10 changes: 10 additions & 0 deletions Sources/Swiftly/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ struct List: SwiftlyCommand {

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

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("A new release of swiftly is available")
ctx.print("Please run `swiftly self-update` to update.")
}
}

let selector = try self.toolchainSelector.map { input in
try ToolchainSelector(parsing: input)
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/Swiftly/ListAvailable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ struct ListAvailable: SwiftlyCommand {

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

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("A new release of swiftly is available")
ctx.print("Please run `swiftly self-update` to update.")
}
}

let selector = try self.toolchainSelector.map { input in
try ToolchainSelector(parsing: input)
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/Swiftly/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ struct Run: SwiftlyCommand {
mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try validateSwiftly(ctx)

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("A new release of swiftly is available")
ctx.print("Please run `swiftly self-update` to update.")
}
}

// Handle the specific case where help is requested of the run subcommand
if command == ["--help"] {
throw CleanExit.helpRequest(self)
Expand Down
10 changes: 10 additions & 0 deletions Sources/Swiftly/Uninstall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ struct Uninstall: SwiftlyCommand {

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

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("A new release of swiftly is available")
ctx.print("Please run `swiftly self-update` to update.")
}
}

let startingConfig = try Config.load(ctx)

let toolchains: [ToolchainVersion]
Expand Down
10 changes: 10 additions & 0 deletions Sources/Swiftly/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ struct Update: SwiftlyCommand {

public mutating func run(_ ctx: SwiftlyCoreContext) async throws {
try validateSwiftly(ctx)

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("A new release of swiftly is available")
ctx.print("Please run `swiftly self-update` to update.")
}
}

var config = try Config.load(ctx)

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

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

let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease()
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version
defer {
if shouldUpdateSwiftly {
ctx.print("A new release of swiftly is available")
ctx.print("Please run `swiftly self-update` to update.")
}
}

var config = try Config.load(ctx)

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