2016-11-20 01:11:22 +01:00
|
|
|
# smartinteract
|
|
|
|
interact with terminal users
|
|
|
|
|
|
|
|
## Availabililty
|
2016-11-20 01:13:33 +01:00
|
|
|
[](https://www.npmjs.com/package/smartinteract)
|
|
|
|
[](https://gitlab.com/pushrocks/smartinteract)
|
|
|
|
[](https://github.com/pushrocks/smartinteract)
|
|
|
|
[](https://pushrocks.gitlab.io/smartinteract/)
|
2016-11-20 01:11:22 +01:00
|
|
|
|
|
|
|
## Status for master
|
2016-11-20 01:13:33 +01:00
|
|
|
[](https://gitlab.com/pushrocks/smartinteract/commits/master)
|
|
|
|
[](https://gitlab.com/pushrocks/smartinteract/commits/master)
|
|
|
|
[](https://david-dm.org/pushrocks/smartinteract)
|
|
|
|
[](https://www.bithound.io/github/pushrocks/smartinteract/master/dependencies/npm)
|
|
|
|
[](https://www.bithound.io/github/pushrocks/smartinteract)
|
2016-11-20 01:11:22 +01:00
|
|
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
|
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
|
|
[](http://standardjs.com/)
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
We recommend the use of TypeScript for best in class intellesense
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
import { SmartInteract } from 'smartinteract'
|
|
|
|
|
|
|
|
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
2016-11-20 22:24:09 +01:00
|
|
|
name: 'question1',
|
2016-11-20 01:11:22 +01:00
|
|
|
type: 'input',
|
|
|
|
message: 'Who are you?',
|
|
|
|
default: 'Somebody',
|
|
|
|
validate: (inputString) => { return true } // implement your own validation
|
|
|
|
}])
|
2016-12-10 17:30:04 +01:00
|
|
|
myInteract.addQuestions([ ... ]) // add more questions
|
|
|
|
myInteract.runQueue()
|
2016-11-20 22:24:09 +01:00
|
|
|
.then(answerBucket => { // the bucket has all the answers of the completed queue
|
|
|
|
let answerQuestion1 = answerBucket.getAnswerFor('question1')
|
2016-11-20 01:11:22 +01:00
|
|
|
// do something with the answers
|
|
|
|
})
|
|
|
|
|
2016-11-20 22:24:09 +01:00
|
|
|
// alternatively use .askQuestion() for more direct control
|
2016-12-10 17:30:04 +01:00
|
|
|
myInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
2016-11-20 22:24:09 +01:00
|
|
|
name: 'question2',
|
|
|
|
type: 'confirm',
|
|
|
|
message: 'Do you speak English?',
|
|
|
|
default: true,
|
|
|
|
validate: (inputString) => { return true } // implement your own validation
|
|
|
|
}().then(answerObject => {
|
|
|
|
// answerObject looks like { name: 'question2', value: true }
|
|
|
|
})
|
2016-11-20 01:14:46 +01:00
|
|
|
```
|
|
|
|
|
2016-11-20 22:24:09 +01:00
|
|
|
### Environment
|
|
|
|
In some environments like CI there is no user input to be expected.
|
|
|
|
smartinteract will always directyl create an answer from the default value
|
|
|
|
|
2016-11-20 01:14:46 +01:00
|
|
|
[](https://push.rocks)
|