-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
414 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright (c) Vatsal Manot | ||
// | ||
|
||
#if os(macOS) | ||
|
||
import FoundationX | ||
import Swift | ||
import System | ||
|
||
extension Process { | ||
public enum PipeName: Codable, Hashable, Sendable { | ||
case standardInput | ||
case standardOutput | ||
case standardError | ||
} | ||
} | ||
|
||
// MARK: - Supplementary | ||
|
||
public protocol _ProcessPipeProviding { | ||
func pipe( | ||
named name: Process.PipeName | ||
) -> Pipe? | ||
} | ||
|
||
extension _ProcessPipeProviding { | ||
public func name(of pipe: Pipe) throws -> Process.PipeName { | ||
if pipe === self.pipe(named: .standardInput) { | ||
return .standardInput | ||
} else if pipe === self.pipe(named: .standardOutput) { | ||
return .standardOutput | ||
} else if pipe === self.pipe(named: .standardError) { | ||
return .standardError | ||
} else { | ||
throw Process.UnrecognizedPipeError.pipe(pipe) | ||
} | ||
} | ||
} | ||
|
||
extension Process: _ProcessPipeProviding { | ||
public func pipe( | ||
named name: PipeName | ||
) -> Pipe? { | ||
switch name { | ||
case .standardInput: | ||
return standardInput as? Pipe | ||
case .standardOutput: | ||
return standardOutput as? Pipe | ||
case .standardError: | ||
return standardError as? Pipe | ||
} | ||
} | ||
} | ||
|
||
extension _AsyncProcess: _ProcessPipeProviding { | ||
public typealias PipeName = Process.PipeName | ||
|
||
public func pipe( | ||
named name: Process.PipeName | ||
) -> Pipe? { | ||
switch name { | ||
case .standardInput: | ||
return _standardInputPipe | ||
case .standardOutput: | ||
return _standardOutputPipe | ||
case .standardError: | ||
return _standardErrorPipe | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Error Handling | ||
|
||
extension Process { | ||
public enum UnrecognizedPipeError: Swift.Error, @unchecked Sendable { | ||
case pipe(Pipe) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.