Yet an other collection of interactive command line user interfaces base on generator.
npm install qa
var qa = require('qa')
qa(function *(ask) {
if (yield ask({
name: 'like',
type: 'confirm',
message: 'Do you like qa ?'
})) {
var reason = yield ask({
name: 'reason',
type: 'input',
message: 'And why ?'
})
console.log('Thank you! I know why now.')
console.log('Because: ' + reason)
} else {
var suggestion = yield ask({
name: 'suggestion',
type: 'input',
message: 'Have suggestion ?'
})
console.log('Thank you!')
console.log('I will try my best to: ' + suggestion)
}
}).then(function (answers) {
console.log(answers) // { like: true, ... }
})
qa(Generator)
Run an interative command line program using a generator. The generator will be given functional arguments:
-
ask (Function)
It will prompt a question and usingyield
to take answer. Accept an argument (Object) to control prompt, options: (retain question object inInquirer.js
, it's wonderful practice.)- type: (string) Type of prompt, default: input - Possible values: confirm, list, rawlist, password.
- name: (string) Answer's key in answers hash.
- message: (string) The question to print.
- default: (string|number|boolean) Default value(s) to use if nothing is entered.
- choices: (Array) Choices array.
- validate: (Function) Receive the user input and should return true if the value is valid, or return error message to print.
- filter: (Function) Receive the user input and return the filtered value to be used inside the program.
Remove some function type support to be more simple
qa(generator).then(function (answers) { ... })
Run qa
will return promise which can get a key/value hash containing the client answers.
- Key The
name
property of the question object. - Value The answer for specified question, can be
boolean
(confirm),string
(input, rawlist, list) and so on.