A Swift package for interacting with command line interfaces.
Create an interface with
- the URL to the executable,
- an, optional, URL to the executable's working directory,
- and an, optional, dictionary of environment variables.
let interface = Interface(executableURL: ...)
Create a command by implementing the Command
and CommandResponse
protocols.
struct VersionCommand: Command {
typealias Response = VersionCommandResponse
var arguments: [String] {
return ["--version"]
}
}
public struct VersionCommandResponse: CommandResponse {
public let version: String
public init?(response: String?) {
guard let response = response else { return nil }
version = response
}
}
Send commands to the executable through the interface.
do {
try interface.send(VersionCommand()) { response in
print("Version: \(response.version ?? "N/A")")
}
}
catch {
print("Error sending command: \(error)")
}