Skip to content

Commit 592672c

Browse files
committed
[SR-6347] Dynamically determine other tool names
1 parent e4675f6 commit 592672c

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

Sources/Commands/SwiftBuildTool.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SwiftBuildTool: SwiftTool<BuildToolOptions> {
3838
usage: "[options]",
3939
overview: "Build sources into binary products",
4040
args: args,
41-
seeAlso: "swift run, swift package, swift test"
41+
seeAlso: type(of: self).otherToolNames()
4242
)
4343
}
4444

@@ -179,3 +179,9 @@ fileprivate extension BuildSubset {
179179
}
180180
}
181181
}
182+
183+
extension SwiftBuildTool: ToolName {
184+
static var toolName: String {
185+
return "swift build"
186+
}
187+
}

Sources/Commands/SwiftPackageTool.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
3838
usage: "[options] subcommand",
3939
overview: "Perform operations on Swift packages",
4040
args: args,
41-
seeAlso: "swift build, swift run, swift test"
41+
seeAlso: type(of: self).otherToolNames()
4242
)
4343
}
4444
override func runImpl() throws {
@@ -471,3 +471,9 @@ extension PackageToolOptions.CompletionToolMode: StringEnumArgument {
471471
])
472472
}
473473
}
474+
475+
extension SwiftPackageTool: ToolName {
476+
static var toolName: String {
477+
return "swift package"
478+
}
479+
}

Sources/Commands/SwiftRunTool.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class SwiftRunTool: SwiftTool<RunToolOptions> {
9090
usage: "[options] [executable [arguments ...]]",
9191
overview: "Build and run an executable product",
9292
args: args,
93-
seeAlso: "swift build, swift package, swift test"
93+
seeAlso: type(of: self).otherToolNames()
9494
)
9595
}
9696

@@ -188,3 +188,8 @@ public class SwiftRunTool: SwiftTool<RunToolOptions> {
188188
}
189189
}
190190

191+
extension SwiftRunTool: ToolName {
192+
static var toolName: String {
193+
return "swift run"
194+
}
195+
}

Sources/Commands/SwiftTestTool.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class SwiftTestTool: SwiftTool<TestToolOptions> {
116116
usage: "[options]",
117117
overview: "Build and run tests",
118118
args: args,
119-
seeAlso: "swift build, swift run, swift package"
119+
seeAlso: type(of: self).otherToolNames()
120120
)
121121
}
122122

@@ -621,3 +621,9 @@ fileprivate extension Sequence where Iterator.Element == TestSuite {
621621
}
622622
}
623623
}
624+
625+
extension SwiftTestTool: ToolName {
626+
static var toolName: String {
627+
return "swift test"
628+
}
629+
}

Sources/Commands/SwiftTool.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ private class ToolWorkspaceDelegate: WorkspaceDelegate {
104104
}
105105
}
106106

107+
protocol ToolName {
108+
static var toolName: String { get }
109+
}
110+
111+
extension ToolName {
112+
static func otherToolNames() -> String {
113+
let allTools: [ToolName.Type] = [SwiftBuildTool.self, SwiftRunTool.self, SwiftPackageTool.self, SwiftTestTool.self]
114+
return allTools.filter({ $0 != self }).map({ $0.toolName }).joined(separator: ", ")
115+
}
116+
}
117+
107118
public class SwiftTool<Options: ToolOptions> {
108119
/// The original working directory.
109120
let originalWorkingDirectory: AbsolutePath

0 commit comments

Comments
 (0)