🧪 Shell is a µ-library written Swift to run system commands
Clone or download
pepibumur Merge pull request #7 from tuist/succeeds
Add method that returns true if a given command succeeds
Latest commit 91ef0af Jan 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Version 1.0.0 Jan 1, 2019
.github Create project Dec 26, 2018
.vscode Create project Dec 26, 2018
Shell-Carthage.xcodeproj Version 1.1.0 Jan 3, 2019
Shell-Carthage.xcworkspace Add Carthage & CocoaPods support Dec 27, 2018
Sources Add method that returns true if a given command succeeds Jan 4, 2019
Tests/ShellTests Add method that returns true if a given command succeeds Jan 4, 2019
docs Version 1.1.0 Jan 3, 2019
.editorconfig Create project Dec 26, 2018
.gitignore Update RELEASE process Jan 1, 2019
.jazzy.yaml Version 0.1.0 Dec 27, 2018
.prettierrc Create project Dec 26, 2018
.ruby-version Bump ruby version Jan 1, 2019
.swift-version Create project Dec 26, 2018
.swiftlint.yml Create project Dec 26, 2018
CHANGELOG.md Update CHANGELOG Jan 4, 2019
Cartfile Bump result to 4.1.0 Jan 3, 2019
Cartfile.resolved Bump result to 4.1.0 Jan 3, 2019
Dangerfile Create project Dec 26, 2018
Gemfile Version 1.0.0 Jan 1, 2019
Gemfile.lock Version 1.0.0 Jan 1, 2019
Info.plist Add Carthage & CocoaPods support Dec 27, 2018
LICENSE.md Create project Dec 26, 2018
Makefile Update RELEASE process Jan 1, 2019
Package.resolved Bump result to 4.1.0 Jan 3, 2019
Package.swift Bump result to 4.1.0 Jan 3, 2019
Project.swift Refactor API to use Result instead of throws Jan 1, 2019
README.md Version 1.0.2 Jan 1, 2019
RELEASE.md Version 1.1.0 Jan 3, 2019
Shell.podspec Version 1.1.0 Jan 3, 2019
ShellTesting.podspec Version 1.1.0 Jan 3, 2019

README.md

🧪 Shell

Shell is a µ-library written Swift to run shell tasks.

CircleCI Swift Package Manager Release Code Coverage Slack License Say Thanks! Join the community on Spectrum

Install 🛠

Swift Package Manager

Add the dependency in your Package.swift file:

let package = Package(
    name: "myproject",
    dependencies: [
        .package(url: "https://github.com/tuist/shell.git", .upToNextMajor(from: "1.0.2")),
        ],
    targets: [
        .target(
            name: "myproject",
            dependencies: ["shell"]),
        ]
)

CocoaPods

Add the following line to your project Podfile:

pod "Shell", "1.0.2"

Carthage

Add the following line to your project Cartfile:

github "tuist/shell" "1.0.2"

Marathon

If you want to use Shell in a Marathon script, either add it to your Marathonfile (see the Marathon repo for instructions on how to do that), or point Marathon to Shell using the inline dependency syntax:

import Shell // https://github.com/tuist/shell.git

Usage 🚀

To run commands in the system, you need to create an instance of Shell:

let shell = Shell()

Shell exposes methods for running the commands synchronously, asynchronously, and capturing the output:

// Synchronous running
let result = shell.sync(["xcodebuild", "-project", "Shell", "-scheme", "Shell"])

// Asynchronous running
shell.async(["xcodebuild", "-project", "Shell", "-scheme", "Shell"]) { result in
  // Process the result
})

// Capturing output
let result = shell.capture(["xcode-select", "-p"])

Testing

We understand how inconvenient testing might be in Swift and thus, we designed Shell's API to facilitate testing by avoiding many syntactic sugar and static interfaces. The library comes with a library, ShellTesting that you can import in your tests target to mock the Shell interface and stub the result of running commands:

import ShellTesting

let mock = Shell.mock()
let xcodebuild = XcodeBuild(shell: mock)

shell.succeed(["xcodebuild", "-project", "Shell.xcodeproj", "-scheme", "Shell"])

XCTAssertNoThrow(try xcodebuild.build(project: "Shell.xcodeproj", scheme: "Shell"))

Setup for development 👩‍💻

  1. Git clone: git@github.com:tuist/shell.git
  2. Generate Xcode project with swift package generate-xcodeproj.
  3. Open Shell.xcodeproj.
  4. Have fun 🤖

Open source

Tuist is a proud supporter of the Software Freedom Conservacy

Become a Conservancy Supporter!