{%= example(read('example.js'), name) %}
Screen capture
See the working examples.
See the working examples.
var questions = require('{%= name %}')();
// question type "input" is used by default
questions
.set('name', 'What is your name?')
.ask('name', function (err, answers) {
console.log(answers);
});
[inquirer2][]
You may optionally pass your own instance of inquirer to the constructor:
// on the options
var questions = require('{%= name %}');
var questions = new Questions({
inquirer: require('inquirer2')
});
// or if inquirer is the only thing passed
var questions = new Questions(require('inquirer2'));
question-cache is a wrapper around [inquirer2][]. If you have any issues related to the interface (like scrolling, colors, styling, etc), then please create an issue on the [inquirer2][] project.
Asking questions
The simplest way to ask a question is by passing a string and a callback:
questions.ask('name', function (err, answers) {
console.log(answers);
});
Ask all cached questions
questions.ask(function (err, answers) {
console.log(answers);
});
{%= apidocs("index.js") %}
See the working examples.
Qestions may be cached using object-path notatation (e.g. a.b.c
).
Example
All of the following will be cached on the name
object:
questions
.set('name.first', 'What is your first name?')
.set('name.middle', 'What is your middle name?')
.set('name.last', 'What is your last name?')
Dot notation usage
When cached using dot-notation, there are a few different ways questions that may be asked.
Ask a single name
question:
questions.ask('name.first', function (err, answers) {
console.log(answers);
});
Ask all name
questions, first
, middle
and last
:
questions.ask('name', function (err, answers) {
console.log(answers);
});
Ask specific questions on name
:
questions.ask(['name.first', 'name.last'], function (err, answers) {
console.log(answers);
});
Ask specific questions on name
:
questions
.set('name.first', {
message: 'What is your first name?',
})
.set('name.last', {
message: 'What is your last name?',
})
.set('foo', {
message: 'Any thoughts about foo?',
})
questions.ask(['name', 'foo'], function (err, answers) {
console.log(answers);
});
Ask one question at a time, based on feedback:
questions.ask('name.first', function (err, answers) {
console.log(answers);
//=> {name: { first: 'Brian' }}
questions.ask('name.last', function (err, answers) {
console.log(answers);
//=> {name: { last: 'Woodward' }}
});
});
Given you have the following questions:
questions
.set('name.first', 'What is your first name?')
.set('name.last', 'What is your last name?')
.set('foo', 'Any thoughts about foo?')
.set('bar', 'Any thoughts about bar?')
The following will ask questions: name.first
, name.last
and foo
questions.ask(['name', 'foo'], function (err, answers) {
console.log(answers);
});