Swiftpack.co - Package - tuist/shell

๐Ÿงช Shell

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

CircleCI Swift Package Manager Release Code Coverage Slack License

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: "2.2.0")),
        ],
    targets: [
        .target(
            name: "myproject",
            dependencies: ["Shell"]),
        ]
)

CocoaPods

Add the following line to your project Podfile:

pod "Shell", "2.2.0"
pod "ShellTesting", "2.2.0"
pod "RxShell", "2.2.0"

Carthage

Add the following line to your project Cartfile:

github "tuist/shell" "2.2.0"

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

RxShell ๐Ÿ’ƒ

Shell comes with a package, RxShell that adds a reactive extension using RxSwift to the interface of Shell.

subject.run(["xcodebuild", "-project", "Shell", "-scheme", "Shell"]).subscribe {
  print("Compilation completed")
}

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!

Github

link
Stars: 48

Used By

Total: 2

Releases

2.2.0 - 2019-09-27 11:11:19

Changed

  • Update RxSwift to 5.0.1 by @pepibumur.

Added

  • Xcode 11 support by @pepibumur.

2.1.3 - 2019-09-15 09:51:53

Fixed

  • A bug that caused the process runner to consume a lot of memory because the output pipes were not getting closed. By @pepibumur.

2.1.2 - 2019-05-30 16:57:39

Changed

  • Make stdout and stderr public.

2.1.1 - 2019-05-30 16:46:25

Changed

  • Make collect() method public.

2.1.0 - 2019-05-30 16:20:56

Added

  • RxSwift package by @pepibumur.

2.0.3 - 2019-04-06 15:49:30

Fixed

  • Carthage dependency to PathKit by @pepibumur.

2.0.2 - 2019-04-05 10:05:08

Fixed

  • Remove residual print by @pepibumur.

2.0.1 - 2019-04-02 07:06:11

Changed

  • Bump PathKit version to 1.0.0 https://github.com/tuist/shell/pull/11 by @pepibumur.

2.0.0 - 2019-03-28 16:21:49

Added

  • Breaking: Swift 5 support https://github.com/tuist/shell/pull/10 by @pepibumur.

1.2.1 - 2019-03-26 20:00:11

Fixed

  • File handlers not getting deallocated after the task completes https://github.com/tuist/shell/pull/9 by @pepibumur.

1.2.0 - 2019-03-25 23:12:44

Fixed

  • Race condition in ProcessRunner https://github.com/tuist/shell/pull/8 by @pepibumur.

Added

  • Shell.succeeds method https://github.com/tuist/shell/pull/7 by @pepibumur.

1.1.0 - 2019-01-03 09:59:58

Changed

  • Bump Result to 4.1.0 https://github.com/tuist/shell/pull/6 by @pepibumur.

1.0.2 - 2019-01-01 22:10:55

Added

  • Tests https://github.com/tuist/shell/pull/5 by @pepibumur.

Removed

  • Breaking Remove throws that are not required https://github.com/tuist/shell/pull/4 by @pepibumur.

1.0.1 - 2019-01-01 10:39:13

Fixed

  • Shell returning an error even if the command succeeded by @pepibumur.

1.0.0 - 2019-01-01 10:12:39

Changed

  • Breaking Refactor API to use the Result type instead of throws https://github.com/tuist/shell/pull/3

0.3.2 - 2018-12-30 08:10:22

Fixed

  • Remove @testable imports from ShellTesting by @pepibumur.

0.3.1 - 2018-12-30 08:10:08

Added

  • ShellTesting.podspec by @pepibumur.

0.3.0 - 2018-12-29 23:02:59

Added

  • Add Shell.lookupExecutable method https://github.com/tuist/shell/pull/2 by @pepibumur.

0.2.0 - 2018-12-28 08:42:52

Changed

  • Make MockShell methods public https://github.com/tuist/shell/pull/1

0.1.0 - 2018-12-27 14:55:32

  • ๐ŸŽ‰ First version of the library