## Example ```js {%= example(read('example.js'), name) %} ``` **Screen capture** screen shot 2015-07-13 at 8 05 20 am See the [working examples](./examples). ## Basic Usage See the [working examples](./examples). ```js 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: ```js // 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')); ``` ## Getting started 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: ```js questions.ask('name', function (err, answers) { console.log(answers); }); ``` **Ask all cached questions** ```js questions.ask(function (err, answers) { console.log(answers); }); ``` ## API {%= apidocs("index.js") %} ## Dot notation See the [working examples](./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: ```js 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. ### Dot notation usage #### ask one Ask a single `name` question: ```js questions.ask('name.first', function (err, answers) { console.log(answers); }); ``` #### ask all "name" questions Ask all `name` questions, `first`, `middle` and `last`: ```js questions.ask('name', function (err, answers) { console.log(answers); }); ``` #### array of questions Ask specific questions on `name`: ```js questions.ask(['name.first', 'name.last'], function (err, answers) { console.log(answers); }); ``` #### ask all questions Ask specific questions on `name`: ```js 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); }); ``` #### nested questions Ask one question at a time, based on feedback: ```js 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' }} }); }); ``` ## More examples ### Mixture of dot notation and non-dot-notation Given you have the following questions: ```js 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` ```js questions.ask(['name', 'foo'], function (err, answers) { console.log(answers); }); ```