Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
12 changes: 8 additions & 4 deletions Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct Install: SwiftlyCommand {
))
var version: String

@Flag(name: .shortAndLong, help: "Mark the newly installed toolchain as in-use.")
var use: Bool = false

@Option(help: ArgumentHelp(
"A GitHub authentiation token to use for any GitHub API requests.",
discussion: """
Expand All @@ -57,10 +60,10 @@ struct Install: SwiftlyCommand {
let selector = try ToolchainSelector(parsing: self.version)
HTTP.githubToken = self.token
let toolchainVersion = try await self.resolve(selector: selector)
try await Self.execute(version: toolchainVersion)
try await Self.execute(version: toolchainVersion, use: self.use)
}

internal static func execute(version: ToolchainVersion) async throws {
internal static func execute(version: ToolchainVersion, use: Bool) async throws {
var config = try Config.load()

guard !config.installedToolchains.contains(version) else {
Expand Down Expand Up @@ -158,8 +161,9 @@ struct Install: SwiftlyCommand {
config.installedToolchains.insert(version)
try config.save()

// If this is the first installed toolchain, mark it as in-use.
if config.inUse == nil {
// If this is the first installed toolchain, mark it as in-use regardless of whether the
// --use argument was provided.
if use || config.inUse == nil {
try await Use.execute(version, config: &config)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftly/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct Update: SwiftlyCommand {
}

print("updating \(oldToolchain) -> \(newToolchain)")
try await Install.execute(version: newToolchain)
try await Install.execute(version: newToolchain, use: false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know update hasn't been merged yet but shouldn't swiftly update also default to using the newly updated toolchain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just in here to have the existing update code compile, but it'll be changed in #67. The planned logic for this is if the toolchain being updated is the one that is in use, then the newly installed one will be used, otherwise no.

try Swiftly.currentPlatform.uninstall(oldToolchain)
print("successfully updated \(oldToolchain) -> \(newToolchain)")
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/SwiftlyTests/InstallTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,18 @@ final class InstallTests: SwiftlyTests {
try await self.validateInUse(expected: ToolchainVersion(major: 5, minor: 7, patch: 0))
}
}

/// Verify that the installed toolchain will be marked as in-use if the --use flag is specified.
func testInstallUseFlag() async throws {
try await self.withTestHome {
try self.installMockedToolchain(toolchain: Self.oldStable)
var use = try self.parseCommand(Use.self, ["use", Self.oldStable.name])
try await use.run()
try await validateInUse(expected: Self.oldStable)

var installOther = try self.parseCommand(Install.self, ["install", "--use", Self.newStable.name])
try await installOther.run()
try await self.validateInUse(expected: Self.newStable)
}
}
}