Skip to content

Commit 91e6101

Browse files
committed
Update Shell interface
1 parent a354d01 commit 91e6101

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import XcbeautifyLib
1010

1111
public protocol ShellService {
1212
func execute(arguments: [String]) throws
13+
func executeWithVisibleOutput(arguments: [String]) throws
1314
func executeWithResult(arguments: [String]) throws -> String
1415
func executeWithXCBeautify(arguments: [String]) throws
1516
}
@@ -24,17 +25,21 @@ final class ShellServiceImpl: ShellService {
2425
}
2526

2627
func execute(arguments: [String]) throws {
27-
try executeTask(arguments: arguments)
28+
try executeTask(arguments: arguments, isOutputVisible: verboseController.isVerbose())
29+
}
30+
31+
func executeWithVisibleOutput(arguments: [String]) throws {
32+
try executeTask(arguments: arguments, isOutputVisible: true)
2833
}
2934

3035
func executeWithResult(arguments: [String]) throws -> String {
31-
return try executeTask(arguments: arguments)
36+
return try executeTask(arguments: arguments, isOutputVisible: verboseController.isVerbose())
3237
}
3338

34-
@discardableResult private func executeTask(arguments: [String]) throws -> String {
39+
@discardableResult private func executeTask(arguments: [String], isOutputVisible: Bool) throws -> String {
3540
let output = CaptureStream()
3641
let error = CaptureStream()
37-
let outputStream = makeOutputStream(captureStream: output)
42+
let outputStream = makeOutputStream(captureStream: output, isOutputVisible: isOutputVisible)
3843

3944
let command = arguments.joined(separator: " ")
4045
let task = Task(executable: "/bin/bash", arguments: ["-c", command], stdout: outputStream, stderr: error)
@@ -53,8 +58,8 @@ final class ShellServiceImpl: ShellService {
5358
return outputString
5459
}
5560

56-
private func makeOutputStream(captureStream: CaptureStream) -> WritableStream {
57-
if verboseController.isVerbose() {
61+
private func makeOutputStream(captureStream: CaptureStream, isOutputVisible: Bool) -> WritableStream {
62+
if isOutputVisible {
5863
return SplitStream(streams: [captureStream, WriteStream.stdout])
5964
} else {
6065
return captureStream

0 commit comments

Comments
 (0)