Swiftpack.co - colinc86/CommandInterface as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by colinc86.
colinc86/CommandInterface v0.2.9
A Swift package for interacting with command line interfaces.
⭐️ 0
🕓 2 weeks ago
.package(url: "https://github.com/colinc86/CommandInterface.git", from: "v0.2.9")


A Swift package for interacting with command line interfaces.

Creating an Interface

Create an interface with

  1. the URL to the executable,
  2. an, optional, URL to the executable's working directory,
  3. and an, optional, dictionary of environment variables.
let interface = Interface(executableURL: ...)

Creating Commands

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

Sending Commands

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)")


Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics