From 0e7851251fb7e242ee5d14461d4a02b697942b75 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Thu, 3 Apr 2025 11:13:01 -0400 Subject: [PATCH 1/2] Add --print-location flag to swiftly list subcommand --- Sources/Swiftly/List.swift | 11 +++++++++++ Tests/SwiftlyTests/ListTests.swift | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Sources/Swiftly/List.swift b/Sources/Swiftly/List.swift index 1757532e..56a81b88 100644 --- a/Sources/Swiftly/List.swift +++ b/Sources/Swiftly/List.swift @@ -33,6 +33,9 @@ struct List: SwiftlyCommand { )) var toolchainSelector: String? + @Flag(name: .shortAndLong, help: "Print the location of the toolchains prefixed with the version - .") + var printLocation: Bool = false + internal mutating func run() async throws { try validateSwiftly() let selector = try self.toolchainSelector.map { input in @@ -42,6 +45,14 @@ struct List: SwiftlyCommand { var config = try Config.load() let toolchains = config.listInstalledToolchains(selector: selector).sorted { $0 > $1 } + + guard !self.printLocation else { + for toolchain in toolchains { + SwiftlyCore.print("\(toolchain.name) - \(Swiftly.currentPlatform.findToolchainLocation(toolchain).path)") + } + + return + } let (inUse, _) = try await selectToolchain(config: &config) let printToolchain = { (toolchain: ToolchainVersion) in diff --git a/Tests/SwiftlyTests/ListTests.swift b/Tests/SwiftlyTests/ListTests.swift index 6724ab97..b1598757 100644 --- a/Tests/SwiftlyTests/ListTests.swift +++ b/Tests/SwiftlyTests/ListTests.swift @@ -43,7 +43,7 @@ final class ListTests: SwiftlyTests { } var list = try self.parseCommand(List.self, args) - let output = try await list.runWithMockedIO() + var output = try await list.runWithMockedIO() let parsedToolchains = output.compactMap { outputLine in Self.allToolchains.first { @@ -56,6 +56,20 @@ final class ListTests: SwiftlyTests { throw SwiftlyTestError(message: "unexpected listed toolchains in \(output)") } + // Check that the print location flag runs as expected + list = try self.parseCommand(List.self, args + ["--print-location"]) + output = try await list.runWithMockedIO() + + let toolchainLocations = output.compactMap { outputLine in + Self.allToolchains.first { + outputLine.contains("\($0.name) - \(Swiftly.currentPlatform.findToolchainLocation($0).path)") + } + } + + guard toolchainLocations.count == parsedToolchains.count else { + throw SwiftlyTestError(message: "list --print-location didn't yield the same toolchains as plain list") + } + return parsedToolchains } From af7ef950c18bcc7cbb5a42eaf622d9f898fbfcd9 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Thu, 3 Apr 2025 11:23:19 -0400 Subject: [PATCH 2/2] Update the docs --- Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md b/Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md index 8a667e17..bebc36c7 100644 --- a/Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md +++ b/Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md @@ -281,7 +281,7 @@ Finally, all installed toolchains can be uninstalled by specifying 'all': List installed toolchains. ``` -swiftly list [] [--version] [--help] +swiftly list [] [--print-location] [--version] [--help] ``` **toolchain-selector:** @@ -307,6 +307,11 @@ The installed snapshots for a given devlopment branch can be listed by specifyin $ swiftly list 5.7-snapshot +**--print-location:** + +*Print the location of the toolchains prefixed with the version - .* + + **--version:** *Show the version.*