Skip to content

Commit dbd5e29

Browse files
committed
wip
1 parent cfa9f3e commit dbd5e29

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-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/raptorxcz/xcbeautify", revision: "1bd38b6a64bb447c264fbdfc1b453bf8065b8ec6"),
1516
],
1617
targets: [
1718
.target(name: "SwiftTools", dependencies: [
1819
"Swinject",
1920
"SwinjectAutoregistration",
2021
"SwiftCLI",
22+
.product(name: "XcbeautifyLib", package: "xcbeautify"),
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

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

0 commit comments

Comments
 (0)