Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
69592933aa | |||
10074b5888 | |||
fe9564e37c | |||
fa5f2d0267 |
@ -25,34 +25,7 @@ smart cli interaction
|
|||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { SmartInteract } from 'smartinteract'
|
|
||||||
|
|
||||||
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
|
||||||
name: 'question1',
|
|
||||||
type: 'input',
|
|
||||||
message: 'Who are you?',
|
|
||||||
default: 'Somebody',
|
|
||||||
validate: (inputString) => { return true } // implement your own validation
|
|
||||||
}])
|
|
||||||
myInteract.addQuestions([ ... ]) // add more questions
|
|
||||||
myInteract.runQueue()
|
|
||||||
.then(answerBucket => { // the bucket has all the answers of the completed queue
|
|
||||||
let answerQuestion1 = answerBucket.getAnswerFor('question1')
|
|
||||||
// do something with the answers
|
|
||||||
})
|
|
||||||
|
|
||||||
// alternatively use .askQuestion() for more direct control
|
|
||||||
myInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
|
||||||
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 }
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartinteract",
|
"name": "@pushrocks/smartinteract",
|
||||||
"version": "2.0.5",
|
"version": "2.0.7",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartinteract",
|
"name": "@pushrocks/smartinteract",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "2.0.5",
|
"version": "2.0.7",
|
||||||
"description": "smart cli interaction",
|
"description": "smart cli interaction",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
62
readme.md
Normal file
62
readme.md
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# smartinteract
|
||||||
|
|
||||||
|
smart cli interaction
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
|
||||||
|
[](https://www.npmjs.com/package/smartinteract)
|
||||||
|
[](https://GitLab.com/pushrocks/smartinteract)
|
||||||
|
[](https://github.com/pushrocks/smartinteract)
|
||||||
|
[](https://pushrocks.gitlab.io/smartinteract/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
[](https://GitLab.com/pushrocks/smartinteract/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smartinteract/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smartinteract)
|
||||||
|
[](https://david-dm.org/pushrocks/smartinteract)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartinteract/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartinteract)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { SmartInteract } from 'smartinteract'
|
||||||
|
|
||||||
|
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
||||||
|
name: 'question1',
|
||||||
|
type: 'input',
|
||||||
|
message: 'Who are you?',
|
||||||
|
default: 'Somebody',
|
||||||
|
validate: (inputString) => { return true } // implement your own validation
|
||||||
|
}])
|
||||||
|
myInteract.addQuestions([ ... ]) // add more questions
|
||||||
|
myInteract.runQueue()
|
||||||
|
.then(answerBucket => { // the bucket has all the answers of the completed queue
|
||||||
|
let answerQuestion1 = answerBucket.getAnswerFor('question1')
|
||||||
|
// do something with the answers
|
||||||
|
})
|
||||||
|
|
||||||
|
// alternatively use .askQuestion() for more direct control
|
||||||
|
myInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
||||||
|
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 }
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
@ -1 +1,2 @@
|
|||||||
export * from './smartinteract.classes.smartinteract';
|
export * from './smartinteract.classes.smartinteract';
|
||||||
|
export * from './smartinteract.classes.answerbucket';
|
@ -5,20 +5,20 @@ import { IAnswerObject } from './smartinteract.classes.smartinteract';
|
|||||||
* class AnswerBucket holds answers
|
* class AnswerBucket holds answers
|
||||||
*/
|
*/
|
||||||
export class AnswerBucket {
|
export class AnswerBucket {
|
||||||
answerMap = new plugins.lik.Objectmap<IAnswerObject>();
|
private answerMap = new plugins.lik.Objectmap<IAnswerObject>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add an answer to the bucket
|
* add an answer to the bucket
|
||||||
*/
|
*/
|
||||||
addAnswer(answerArg: IAnswerObject) {
|
public addAnswer(answerArg: IAnswerObject) {
|
||||||
this.answerMap.add(answerArg);
|
this.answerMap.add(answerArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets an answer for a specific name
|
* gets an answer for a specific name
|
||||||
*/
|
*/
|
||||||
getAnswerFor(nameArg: string) {
|
public getAnswerFor(nameArg: string) {
|
||||||
let answer = this.answerMap.find(answerArg => {
|
const answer = this.answerMap.find(answerArg => {
|
||||||
return answerArg.name === nameArg;
|
return answerArg.name === nameArg;
|
||||||
});
|
});
|
||||||
return answer ? answer.value : null;
|
return answer ? answer.value : null;
|
||||||
@ -27,7 +27,7 @@ export class AnswerBucket {
|
|||||||
/**
|
/**
|
||||||
* gets all answers as array
|
* gets all answers as array
|
||||||
*/
|
*/
|
||||||
getAllAnswers() {
|
public getAllAnswers() {
|
||||||
return this.answerMap.getArray();
|
return this.answerMap.getArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user