Skip to content

Commit

Permalink
simplified info
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Aug 26, 2024
1 parent 4a24c13 commit e007593
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Sources/Runner/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ open class Runner {
process.arguments = arguments
process.environment = environment

let stdout = info(for: stdoutMode, pipe: &process.standardOutput)
let stderr = info(for: stderrMode, pipe: &process.standardError)
let stdout = info(for: stdoutMode)
if let stdout {
process.standardOutput = stdout.pipe
}
let stderr = info(for: stderrMode)
if let stderr {
process.standardError = stderr.pipe
}

try process.run()
process.waitUntilExit()
Expand Down Expand Up @@ -182,28 +188,31 @@ open class Runner {
process.arguments = arguments
process.environment = environment

let stdout = info(for: stdoutMode, pipe: &process.standardOutput)
let stderr = info(for: stderrMode, pipe: &process.standardError)
let stdout = info(for: stdoutMode)
if let stdout {
process.standardOutput = stdout.pipe
}
let stderr = info(for: stderrMode)
if let stderr {
process.standardError = stderr.pipe
}

try process.run()
return RunningProcess(stdout: stdout, stderr: stderr, process: process)
}

func info(for mode: Mode, pipe: inout Any?) -> PipeInfo? {
func info(for mode: Mode) -> PipeInfo? {
switch mode {
case .passthrough:
return nil
case .capture:
let outInfo = PipeInfo(queue: queue)
pipe = outInfo.pipe
return outInfo
case .tee:
let outInfo = PipeInfo(tee: FileHandle.standardOutput, queue: queue)
pipe = outInfo.pipe
return outInfo
case .callback(let block):
let outInfo = PipeInfo(queue: queue, callback: block)
pipe = outInfo.pipe
return outInfo

}
Expand Down

0 comments on commit e007593

Please sign in to comment.