Swiftpack.co - taji-taji/swift-shell as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by taji-taji.
taji-taji/swift-shell 1.0.1
Simple Shell Executor with Swift.
⭐️ 0
🕓 3 weeks ago
.package(url: "https://github.com/taji-taji/swift-shell.git", from: "1.0.1")

:shell: Swift Shell

Simple shell executor with Swift.

Test MIT License Latest Version Swift Compatibility Platform Compatibility

Requirements

  • Swift 5.5.2 or later

Usage

Package.swift

To use the SwiftShell library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/taji-taji/swift-shell.git", from: "1.0.0")

Include "SwiftShell" as a dependency for your executable target:

.target(name: "<target>", dependencies: [
    .product(name: "SwiftShell", package: "swift-shell"),
]),

Finally, add import SwiftShell to your source code.

Example

Basic Usage

import SwiftShell

let shell = Shell()

do {
    // Shell is implemented with `callAsFunction`.
    let output = try shell("ls", arguments: ["-l", "-a"])
    print(output)
} catch {
    print(error)
}

Async / Await

import SwiftShell

let shell = Shell()

Task {
    async let output1 = shell("brew install awesome-tool")
    async let output2 = shell("bundle install")

    let result = try await (output1, output2)
    print(result.0)
    print(result.1)
}

Use Environment Variables

Execute with some Environment Variables.

try shell("brew install git",
          additionalEnvironment: ["HOMEBREW_NO_AUTO_UPDATE": "1"])

GitHub

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

Related Packages

Release Notes

1.0.1
3 weeks ago

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