Code Monkey home page Code Monkey logo

rxtask's Introduction

RxTask

An RxSwift implementation of a command line task runner.

GitHub release Build Status codecov docs carthage compatible swift package manager compatible platform macOS language swift 3.0

Linux Compatibility

Currently, RxTask does not support Linux. RxTask relies on some functionality in Foundation that is currently not available in the Linux port. This will be re-evaluated after the Swift 3.1 release. PRs in this area are quite welcome! ๐Ÿ‘

Installation

Carthage

github "RxSwiftCommunity/RxTask"

SPM

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/RxSwiftCommunity/RxSwift.git", majorVersion: 0)
    ]
)

Usage

Create A Task

Creating a task is as simple as providing a launchPath to the executable.

let task = Task(launchPath: "/bin/ls")

Optionally, you can provide arguments, a workingDirectory, and an environment.

let task = Task(launchPath: "/bin/echo", arguments: ["$MESSAGE"], environment: ["MESSAGE": "Hello World!"])

Launch A Task

Tasks can be launched with the launch() method. This produces a self-contained process. This means the same task can be launch()ed multiple times producing separate processes.

TaskEvent

The output of launch() is a Observable<TaskEvent>. TaskEvent is an enum that is used to report significant events in the task lifetime. The possible events are:

  • launch(command: String)
  • stdOut(Data)
  • stdErr(Data)
  • exit(statusCode: Int)

Note: Currently an event is only considered successful if it exits with a statusCode of 0. Other exit statuses will be considered a TaskError.

StdIn

If you create a task that expects input, you can provide an Observable<Data> for stdin when you are launch()ing the Task. Data will be written to stdin as soon as it is emitted by the Observable.

Filtering TaskEvents

If you are only concerned with whether a Task has completed successfully, you can use the built-in operator justExitStatus().

Task(launchPath: "/bin/ls").launch()
    .justExitStatus()
    .subscribe(onNext: { exitStatus in /* ... */ })
    .disposed(by: disposeBag)

Alternatively, if you are only interested in the output of a Task, you can use the operator justOutput(). This will send the output of both stdout and stderr.

Task(launchPath: "/bin/ls").launch()
    .justOutput()
    .subscribe(onNext: { output in /* ... */ })
    .disposed(by: disposeBag)

TaskError

TaskError is an Error that will be emitted under the following situations:

  • uncaughtSignal: The Task terminated with an uncaught signal (e.g. SIGINT).
  • exit(statusCode: Int): The Task exited with a non-zero exit code.

API Reference

Full docs can be found here.

rxtask's People

Contributors

scottrhoyt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxtask's Issues

StdIn

Allow the task to take an input for stdin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.