Skip to content

Commit 0c33db3

Browse files
committed
wip
1 parent cfa9f3e commit 0c33db3

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Package.swift

+2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ let package = Package(
1212
.package(url: "https://github.com/Swinject/Swinject.git", from: "2.8.1"),
1313
.package(url: "https://github.com/Swinject/SwinjectAutoregistration", from: "2.8.1"),
1414
.package(url: "https://github.com/jakeheis/SwiftCLI", exact: "6.0.3"),
15+
.package(url: "https://github.com/cpisciotta/xcbeautify", exact: "2.7.0"),
1516
],
1617
targets: [
1718
.target(name: "SwiftTools", dependencies: [
1819
"Swinject",
1920
"SwinjectAutoregistration",
2021
"SwiftCLI",
22+
"XcbeautifyLib",
2123
]),
2224
.testTarget(
2325
name: "SwiftToolsTests",

Sources/SwiftTools/Build/Domain/BuildInteractor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class BuildInteractorImpl: BuildInteractor {
4747

4848
func test(with arguments: TestArguments) throws {
4949
let arguments = try makeArguments(from: arguments)
50-
try shellService.execute(arguments: arguments)
50+
try shellService.executeWithXCBeautify(arguments: arguments)
5151
}
5252

5353
func testWithLog(with arguments: TestArguments) throws -> String {

Sources/SwiftTools/Common/Shell/Platform/ShellService.swift

+34
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
//
77

88
import SwiftCLI
9+
import XcbeautifyLib
910

1011
public protocol ShellService {
1112
func execute(arguments: [String]) throws
1213
func executeWithResult(arguments: [String]) throws -> String
14+
func executeWithXCBeautify(arguments: [String]) throws
1315
}
1416

1517
final class ShellServiceImpl: ShellService {
@@ -58,4 +60,36 @@ final class ShellServiceImpl: ShellService {
5860
return captureStream
5961
}
6062
}
63+
64+
@discardableResult func executeWithXCBeautify(arguments: [String]) throws {
65+
let output = Term.stdout
66+
let error = CaptureStream()
67+
let printStream = WriteStream.stdout
68+
let parser = Parser(
69+
colored: !disableColoredOutput,
70+
renderer: .terminal,
71+
preserveUnbeautifiedLines: preserveUnbeautified,
72+
additionalLines: { nil }
73+
)
74+
let outputStream = makeBeautifyStream(outputStream: printStream, parser: paraser)
75+
76+
let command = arguments.joined(separator: " ")
77+
let task = Task(executable: "/bin/bash", arguments: ["-c", command], stdout: outputStream)
78+
printService.printVerbose("shell command: '\(command)'")
79+
let exitCode = task.runSync()
80+
81+
guard exitCode == 0 else {
82+
throw ToolsError(description: "shell command: '\(command)' failed with error")
83+
}
84+
}
85+
86+
private func makeBeautifyStream(outputStream: WritableStream, parser: Parser) -> ProcessingStream {
87+
return LineStream { line in
88+
if let formatted = parser.parse(line: line) {
89+
outputStream.write(formatted)
90+
} else {
91+
outputStream.write(line)
92+
}
93+
}
94+
}
6195
}

0 commit comments

Comments
 (0)