https://github.com/jamen/pull-prompt
A CLI prompter for pull-streams
https://github.com/jamen/pull-prompt
Last synced: 9 months ago
JSON representation
A CLI prompter for pull-streams
- Host: GitHub
- URL: https://github.com/jamen/pull-prompt
- Owner: jamen
- License: mit
- Created: 2017-04-10T00:59:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-10T00:59:29.000Z (about 9 years ago)
- Last Synced: 2025-01-12T11:43:47.672Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# pull-prompt
> A CLI prompter for pull-streams
A [pull-stream](https://github.com/pull-stream/pull-stream) that maps questions to answers by prompting the user. It relies on [`prompt-skeleton`](https://npmjs.com/prompt-skeleton) ecosystem.
```js
pull(
values([
{ type: 'text',
message: 'what is the first animal you think of?',
default: 'unicorn' },
{ type: 'confirm',
message: 'is the animal awesome?',
default: true }
]),
prompt(),
collect((err, answers) => {
// ...
})
)
```
See [`examples/`](examples/) for use with state management modules (like [`pull-stream-model`](https://npmjs.com/pull-stream-model) and [`redux`](https://npmjs.com/redux)).
## Installation
```sh
# with npm
npm i -s pull-prompt
# with yarn
yarn add pull-prompt
```
## Usage
### `prompt()`
A [through stream](https://github.com/pull-stream/pull-stream#through) that maps [questions](#questions) to what the user inputs.
```js
pull(
questions(),
prompt(),
collect((err, answers) => {
// ...
})
)
```
### Questions
Questions are objects which have a minimum of `{ type, message }`. They may contain extra properties from the prompt type (e.g. `default`, `suggest`) or the user (e.g. `name: 'license'`)
### `'text'` question
```js
{
type: 'text',
message: 'What is your name?',
default: 'John Doe' // optional
}
```
### `'confirm'` question
```js
{
type: 'confirm',
message: 'Do you agree to the terms?',
default: false, // optional
}
```
### `'autocomplete'` question
```js
{
type: 'autocomplete',
message: 'What country do you live in?',
suggest: function (input) {
// ...
}
}
```
The `suggest` function returns `Promise`. See [`cli-autocomplete`](https://github.com/derhuerst/cli-autocomplete) for more info
---
_Maintained by [Jamen Marz](https://git.io/jamen) (See on [Twitter](https://twitter.com/jamenmarz) and [GitHub](https://github.com/jamen) for questions & updates)_