Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.
You might also be interested in data-store.
(TOC generated by verb using markdown-toc)
Install with npm:
$ npm install --save base-questionsTry running the actual examples if it helps to see the following example in action.
varquestions=require('base-questions');varassemble=require('assemble-core');varstore=require('base-store');varargv=require('base-argv');varapp=assemble();app.use(store());app.use(argv());varargv=app.argv(process.argv.slice(2));app.use(questions(app,argv.options));app.task('ask',function(cb){app.ask(function(err,answers){if(err)returncb(err);console.log(answers);cb();});});app.task('a',function(cb){console.log('task > a!');cb();});app.task('b',function(cb){console.log('task > b!');cb();});app.task('c',function(cb){console.log('task > c!');cb();});app.task('choices',function(cb){app.choices('run',['a','b','c'],function(err,answers){if(err)returncb(err);if(!answers.run.length)returncb();app.build(answers.run,cb);});});app.build('choices',function(err){if(err)returnconsole.log(err);console.log('done!');});Create a confirm question.
Params
name{String}: Question namemsg{String}: Question messagequeue{String|Array}: Name or array of question names.options{Object|Function}: Question options or callback functioncallback{Function}: callback function
Example
app.confirm('file','Want to generate a file?');// equivalent toapp.question({name: 'file',message: 'Want to generate a file?',type: 'confirm'});Create a "choices" question from an array.
Params
name{String}: Question namemsg{String}: Question messagechoices{Array}: Choice itemsqueue{String|Array}: Name or array of question names.options{Object|Function}: Question options or callback functioncallback{Function}: callback function
Example
app.choices('color','Favorite color?',['blue','orange','green']);// orapp.choices('color',{message: 'Favorite color?',choices: ['blue','orange','green']});// orapp.choices({name: 'color',message: 'Favorite color?',choices: ['blue','orange','green']});Add a question to be asked by the .ask method.
Params
name{String}: Question namemsg{String}: Question messagevalue{Object|String}: Question object, message (string), or options object.locale{String}: Optionally pass the locale to use, otherwise the default locale is used.returns{Object}: Returns thethis.questionsobject, for chaining
Example
app.question('beverage','What is your favorite beverage?');// orapp.question('beverage',{type: 'input',message: 'What is your favorite beverage?'});// orapp.question({name: 'beverage'type: 'input',message: 'What is your favorite beverage?'});Ask one or more questions, with the given options and callback.
Params
queue{String|Array}: Name or array of question names.options{Object|Function}: Question options or callback functioncallback{Function}: callback function
Example
// ask all questionsapp.ask(function(err,answers){console.log(answers);});// ask the specified questionsapp.ask(['name','description'],function(err,answers){console.log(answers);});- answer-store: Store answers to user prompts, based on locale and/or current working directory. | homepage
- common-questions: An object of questions commonly used by project generators or when initializing projects. Questions can… more | homepage
- question-store: Ask questions, persist the answers. Basic support for i18n and storing answers based on current… more | homepage
- to-choices: Easily create a normalized inquirer choices question. Supports all of the
choicesquestion types: checkbox… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verbInstall dev dependencies:
$ npm install -d && npm testJon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb-generate-readme, v0.1.31, on October 01, 2016.