ShellInterface 0.3.0

ShellInterface 0.3.0

Héctor Marqués 维护。



ShellInterface

Version License Platform

一个作为 Foundation 的 Process 之上的薄抽象层的 shell 接口。

使用方法

// -- 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)
}

安装

ShellInterface 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中

pod "ShellInterface"

许可证

ShellInterface 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。

替代方案