ShellInterface

master

A shell interface built as a thin abstraction layer over Foundation's Process
hectr/swift-shell-interface

ShellInterface

Version License Platform

A shell interface built as a thin abstraction layer over Foundation's Process.

Usage

// -- Simple use case example:

let shell = ExecuteCommand()
let result = shell.execute(command: "cat",
arguments: ["/tmp/log.0.txt", "/tmp/log.1.txt"],
waitUntilExit: true)

// -- Customization example:

var context = TaskContext()
context.environment = ["HOME": "/Users/me"]
context.workingDirectory = "/tmp/"

let bash = ExecuteCommand(pathToShell: "/bin/bash")
_ = bash.execute(command: "curl", arguments: ["http://example.org"], context: context, waitUntilExit:false)

// -- Error reporting examples:

print(result.standardError)

guard let terminationStatus = result.terminationStatus else {
    throw TaskFailure.stillRunning(domain: #function, code: #line)
}

guard terminationStatus == 0 else {
    throw TaskFailure.nonzeroTerminationStatus(
        domain: #function,
        code: #line,
        terminationStatus: terminationStatus,
        uncaughtSignal: result.terminatedDueUncaughtSignal
    )
}

guard !result.standardOutput.isEmpty else {
    throw TaskFailure.emptyOutput(domain: #function, code: #line)
}

Installation

ShellInterface is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ShellInterface"

License

ShellInterface is available under the MIT license. See the LICENSE file for more info.

Alternatives

Description

  • Swift Tools 4.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Oct 23 2024 08:59:38 GMT-0900 (Hawaii-Aleutian Daylight Time)