diff --git a/Sources/Merge/Intramodular/Process/SystemShell.swift b/Sources/Merge/Intramodular/Process/SystemShell.swift index c981a15..4ceebc2 100644 --- a/Sources/Merge/Intramodular/Process/SystemShell.swift +++ b/Sources/Merge/Intramodular/Process/SystemShell.swift @@ -52,22 +52,41 @@ extension SystemShell { input: String? = nil, environment: Environment = .zsh ) async throws -> Process.RunResult { - let (launchPath, arguments) = try await environment.resolve(command: command) + let process = try await _AsyncProcess( + command: command, + input: input, + environment: environmentVariables, + currentDirectoryURL: currentDirectoryURL, + options: options + ) - let process = try _AsyncProcess( + return try await process.run() + } +} + +extension _AsyncProcess { + public convenience init( + command: String, + input: String? = nil, + shell: SystemShell.Environment = .zsh, + environment: [String: String]? = nil, + currentDirectoryURL: URL? = nil, + options: [_AsyncProcess.Option]? + ) async throws { + let (launchPath, arguments) = try await shell.resolve(command: command) + + try self.init( executableURL: URL(fileURLWithPath: launchPath), arguments: arguments, - environment: self.environmentVariables.merging(environmentVariables, uniquingKeysWith: { $1 }), - currentDirectoryURL: currentDirectoryURL ?? self.currentDirectoryURL, + environment: environment ?? ProcessInfo.processInfo.environment, + currentDirectoryURL: currentDirectoryURL, options: options ) - if let input = input?.data(using: .utf8), !input.isEmpty, let handle = process.standardInputPipe?.fileHandleForWriting { + if let input = input?.data(using: .utf8), !input.isEmpty, let handle = standardInputPipe?.fileHandleForWriting { try? handle.write(contentsOf: input) try? handle.close() } - - return try await process.run() } } #else diff --git a/Sources/Merge/Intramodular/Process/_AsyncProcess.swift b/Sources/Merge/Intramodular/Process/_AsyncProcess.swift index a4be46f..dc77b9d 100644 --- a/Sources/Merge/Intramodular/Process/_AsyncProcess.swift +++ b/Sources/Merge/Intramodular/Process/_AsyncProcess.swift @@ -11,7 +11,7 @@ import System @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) @available(macCatalyst, unavailable) public class _AsyncProcess: Logging { - public let options: [Option] + public let options: Set