Skip to content

Commit eb19d3a

Browse files
committed
Move SwiftTool creation out of individual commands
The SwiftTool initializer performs some global configuration steps, so it isn't really safe to require that individual commands create an instance, even when they don't need one. This moves the customization point to a run(_ swiftTool: SwiftTool) method.
1 parent dbacb35 commit eb19d3a

File tree

5 files changed

+78
-95
lines changed

5 files changed

+78
-95
lines changed

Sources/Commands/SwiftBuildTool.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ struct BuildToolOptions: ParsableArguments {
5555
return allSubsets.first ?? .allExcludingTests
5656
}
5757

58-
@OptionGroup()
59-
var swiftOptions: SwiftToolOptions
60-
6158
/// If the test should be built.
6259
@Flag(help: "Build both source and test targets")
6360
var buildTests: Bool
@@ -76,20 +73,21 @@ struct BuildToolOptions: ParsableArguments {
7673
}
7774

7875
/// swift-build tool namespace
79-
public struct SwiftBuildTool: ParsableCommand {
76+
public struct SwiftBuildTool: SwiftCommand {
8077
public static let configuration = CommandConfiguration(
8178
commandName: "swift build",
8279
abstract: "Build sources into binary products",
8380
discussion: "SEE ALSO: swift run, swift package, swift test",
8481
version: Versioning.currentVersion.completeDisplayString,
8582
helpNames: [.short, .long, .customLong("help", withSingleDash: true)])
8683

84+
@OptionGroup()
85+
var swiftOptions: SwiftToolOptions
86+
8787
@OptionGroup()
8888
var options: BuildToolOptions
8989

90-
public func run() throws {
91-
let swiftTool = try SwiftTool(options: options.swiftOptions)
92-
90+
public func run(_ swiftTool: SwiftTool) throws {
9391
if options.shouldPrintBinPath {
9492
try print(swiftTool.buildParameters().buildPath.description)
9593
return

0 commit comments

Comments
 (0)