shell::test_tube:Shell是用Swift编写的µ库,用于运行系统命令

  • v2_337185
    了解作者
  • 39.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 03:26
    上传日期
:test_tube: 贝壳 Shell是一个由Swift编写的µ库,用于运行Shell任务。 安装 :hammer_and_wrench: 迅捷软件包管理器 在您的Package.swift文件中添加依赖项: let package = Package ( name : " myproject " , dependencies : [ . package ( url : " https://github.com/tuist/shell.git " , . upToNextMajor ( from : " 2.2.0 " )), ], targets : [ . target
shell-master.zip
内容介绍
# 🧪 Shell Shell is a µ-library written Swift to run shell tasks. [![CircleCI](https://circleci.com/gh/tuist/shell.svg?style=svg)](https://circleci.com/gh/tuist/shell) [![Swift Package Manager](https://img.shields.io/badge/swift%20package%20manager-compatible-brightgreen.svg)](https://swift.org/package-manager/) [![Release](https://img.shields.io/github/release/tuist/shell.svg)](https://github.com/tuist/shell/releases) [![Code Coverage](https://codecov.io/gh/tuist/shell/branch/master/graph/badge.svg)](https://codecov.io/gh/tuist/shell) [![Slack](http://slack.tuist.io/badge.svg)](http://slack.tuist.io/) [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/tuist/shell/blob/master/LICENSE.md) ## Install 🛠 ### Swift Package Manager Add the dependency in your `Package.swift` file: ```swift 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: ```ruby pod "Shell", "2.2.0" pod "ShellTesting", "2.2.0" pod "RxShell", "2.2.0" ``` ### Carthage Add the following line to your project Cartfile: ```ruby github "tuist/shell" "2.2.0" ``` ### Marathon If you want to use Shell in a [Marathon](https://github.com/johnsundell/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: ```swift import Shell // https://github.com/tuist/shell.git ``` ## Usage 🚀 To run commands in the system, you need to create an instance of `Shell`: ```swift let shell = Shell() ``` Shell exposes methods for running the commands synchronously, asynchronously, and capturing the output: ```swift // 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: ```swift 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`. ```swift 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](https://sfconservancy.org/) <a href="https://sfconservancy.org/supporter/" rel='nofollow' onclick='return false;'><img src="https://sfconservancy.org/img/supporter-badge.png" width="194" height="90" alt="Become a Conservancy Supporter!" border="0"/></a>
评论
    相关推荐