commander-rxjs
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "commander-rxjs", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A simple adapter to easily use RxJS with commander.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# commander-rxjs | ||
<!-- npm -->[![](https://img.shields.io/npm/v/commander-rxjs.svg?style=flat)](https://www.npmjs.com/package/commander-rxjs) | ||
<!-- travisci -->[![](https://img.shields.io/travis/nickbreaton/commander-rxjs/master.svg?style=flat)](https://travis-ci.org/nickbreaton/commander-rxjs) | ||
<!-- codecov --> [![](https://img.shields.io/codecov/c/github/nickbreaton/commander-rxjs.svg?style=flat)](https://codecov.io/gh/nickbreaton/commander-rxjs) | ||
[![NPM Version](https://img.shields.io/npm/v/commander-rxjs.svg?style=flat-square)](https://www.npmjs.com/package/commander-rxjs) | ||
[![TravisCI](https://img.shields.io/travis/nickbreaton/commander-rxjs/master.svg?style=flat-square)](https://travis-ci.org/nickbreaton/commander-rxjs) | ||
[![Codecov](https://img.shields.io/codecov/c/github/nickbreaton/commander-rxjs.svg?style=flat-square)](https://codecov.io/gh/nickbreaton/commander-rxjs) | ||
@@ -15,3 +15,3 @@ A simple adapter to easily use [RxJS](https://github.com/ReactiveX/RxJS) with [commander](https://github.com/tj/commander.js). | ||
**Note:** `commander` and `rxjs` are both specified as peer dependencies. You must install them alongside `commander-rxjs`. | ||
**Important:** `commander` and `rxjs` are both peer dependencies. You must install them alongside `commander-rxjs`. | ||
@@ -22,31 +22,58 @@ ``` | ||
## Convert commands to observables | ||
## API | ||
`commander-rxjs` provides a `.observe()` function to convert commands an RxJS observable. | ||
### `ObservableCommand` | ||
**Note:** The `.observe()` can be used any place commander's `.action(cb)` function can be used. | ||
`commander` exports an instance of a `Command`: | ||
```js | ||
import program from 'commander'; | ||
program | ||
.command('example') | ||
.action(options => { | ||
// do stuff | ||
}); | ||
program | ||
.parse(proces.argv); | ||
``` | ||
`commander-rxjs` exports an instance of a wrapped `Command` known as an `ObservableCommand`. | ||
The `ObservableCommand` has the exact same API as a `Command`, with the addition of one function, `observe()`, which is used in place of the `.action()` function: | ||
```js | ||
import program from 'commander-rxjs'; | ||
program | ||
.command('order [item]') | ||
.option('--two-day-shipping') | ||
.observe() | ||
.do(command => { | ||
console.log(command.args, command.options); | ||
// --> { item: "JavaScript Stickers" } | ||
// --> { twoDayShipping: true } | ||
}) | ||
.subscribe(); | ||
.command('example') | ||
.observe() | ||
// ... do stream stuff | ||
.subscribe(); | ||
// INPUT: amazon-cli order "JavaScript Stickers" --two-day-shipping | ||
program | ||
.parse(process.argv) | ||
.parse(proces.argv); | ||
``` | ||
### `observe()` | ||
returns an RxJS observable stream with the following data: | ||
```js | ||
{ | ||
args: { | ||
'camelCasedArgument': 'value', | ||
'...': '...' | ||
}, | ||
options: { | ||
'camelCasedOption': 'value', | ||
'...': '...' | ||
}, | ||
command: Command // (commander raw command) | ||
} | ||
``` | ||
## Examples | ||
Be sure to checkout all of the [examples](https://github.com/nickbreaton/commander-rxjs/tree/master/examples). | ||
Then can easily be run by `npm run example:[example-name]`. | ||
Be sure to checkout all of the [examples](https://github.com/nickbreaton/commander-rxjs/tree/master/examples). They can easily be run with `npm run example:[example]`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9401
78