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.* 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 }