base-questions
Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.
Last updated 9 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install base-questions 
SYNC missed versions from official npm registry.

base-questions NPM version NPM downloads Build Status

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.

Table of Contents

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install --save base-questions

Usage

Try running the actual examples if it helps to see the following example in action.

var questions = require('base-questions');
var assemble = require('assemble-core');
var store = require('base-store');
var argv = require('base-argv');

var app = assemble();
app.use(store());
app.use(argv());

var argv = app.argv(process.argv.slice(2));
app.use(questions(app, argv.options));

app.task('ask', function (cb) {
  app.ask(function (err, answers) {
    if (err) return cb(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) return cb(err);
    if (!answers.run.length) return cb();
    app.build(answers.run, cb);
  });
});

app.build('choices', function(err) {
  if (err) return console.log(err);
  console.log('done!');
});

API

.confirm

Create a confirm question.

Params

  • name {String}: Question name
  • msg {String}: Question message
  • queue {String|Array}: Name or array of question names.
  • options {Object|Function}: Question options or callback function
  • callback {Function}: callback function

Example

app.confirm('file', 'Want to generate a file?');

// equivalent to
app.question({
  name: 'file',
  message: 'Want to generate a file?',
  type: 'confirm'
});

.choices

Create a "choices" question from an array.

Params

  • name {String}: Question name
  • msg {String}: Question message
  • choices {Array}: Choice items
  • queue {String|Array}: Name or array of question names.
  • options {Object|Function}: Question options or callback function
  • callback {Function}: callback function

Example

app.choices('color', 'Favorite color?', ['blue', 'orange', 'green']);

// or
app.choices('color', {
  message: 'Favorite color?',
  choices: ['blue', 'orange', 'green']
});

// or
app.choices({
  name: 'color',
  message: 'Favorite color?',
  choices: ['blue', 'orange', 'green']
});

.question

Add a question to be asked by the .ask method.

Params

  • name {String}: Question name
  • msg {String}: Question message
  • value {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 the this.questions object, for chaining

Example

app.question('beverage', 'What is your favorite beverage?');

// or
app.question('beverage', {
  type: 'input',
  message: 'What is your favorite beverage?'
});

// or
app.question({
  name: 'beverage'
  type: 'input',
  message: 'What is your favorite beverage?'
});

.ask

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 function
  • callback {Function}: callback function

Example

// ask all questions
app.ask(function(err, answers) {
  console.log(answers);
});

// ask the specified questions
app.ask(['name', 'description'], function(err, answers) {
  console.log(answers);
});

About

Related projects

  • 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 choices question types: checkbox… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(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 && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.1.31, on October 01, 2016.

Current Tags

  • 0.9.1                                ...           latest (8 years ago)

37 Versions

  • 0.9.1                                ...           8 years ago
  • 0.9.0                                ...           8 years ago
  • 0.8.1                                ...           8 years ago
  • 0.8.0                                ...           8 years ago
  • 0.7.4                                ...           8 years ago
  • 0.7.3                                ...           8 years ago
  • 0.7.2                                ...           8 years ago
  • 0.7.1                                ...           8 years ago
  • 0.7.0                                ...           8 years ago
  • 0.6.6                                ...           9 years ago
  • 0.6.5                                ...           9 years ago
  • 0.6.4                                ...           9 years ago
  • 0.6.3                                ...           9 years ago
  • 0.6.2                                ...           9 years ago
  • 0.6.1                                ...           9 years ago
  • 0.6.0                                ...           9 years ago
  • 0.5.6                                ...           9 years ago
  • 0.5.5                                ...           9 years ago
  • 0.5.4                                ...           9 years ago
  • 0.5.3                                ...           9 years ago
  • 0.5.2                                ...           9 years ago
  • 0.5.1                                ...           9 years ago
  • 0.5.0                                ...           9 years ago
  • 0.4.1                                ...           9 years ago
  • 0.4.0                                ...           9 years ago
  • 0.3.2                                ...           9 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.6                                ...           9 years ago
  • 0.2.5                                ...           9 years ago
  • 0.2.3                                ...           9 years ago
  • 0.2.2                                ...           9 years ago
  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.3                                ...           9 years ago
  • 0.1.2                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE