Skip to content

Latest commit

 

History

History
104 lines (78 loc) · 1.88 KB

.verb.md

File metadata and controls

104 lines (78 loc) · 1.88 KB

Install

{%= include("install-npm", {save: true}) %}

Usage

Question

Pass a string or question object to the constructor:

const Confirm = require('{%= name %}');
const prompt = new Confirm('Do you like chocolate?');

// or
const prompt = new Confirm({
  name: 'chocolate', 
  message: 'Do you like chocolate?'
});

Run the prompt

You can use one of the following two methods for running the prompt:

// async
prompt.ask(function(answer) {
  console.log(answer);
});

// or promise
prompt.run()
  .then(function(answer) {
    console.log(answer);
  });

Examples

const confirm = new Confirm('Like chocolate?')
  .ask(function(answer) {
    console.log(answer);
  });

const confirm = new Confirm('Like chocolate?')
  .run()
  .then(function(answer) {
    console.log(answer);
  });

Usage with [enquirer][]

const Enquirer = require('enquirer');
const enquirer = new Enquirer();

enquirer.register('{%= alias %}', require('{%= name %}'));

Enquirer example

[Enquirer][] supports either the declarative object-oriented (inquirer-style) question format or a more expressive format using the .question method.

Declarative

Inquirer-style declarative format (takes an array or object):

const questions = [
  {
    type: '{%= alias %}',
    name: 'chocolate',
    message: 'Like chocolate?'
  },
  {
    type: '{%= alias %}',
    name: 'vanilla',
    message: 'Like vanilla?'
  }
];

enquirer.ask(questions)
  .then(function(answers) {
    console.log(answers)
  });

Expressive

Pre-define questions and easily compose prompts by passing the name(s) of the prompts to run:

enquirer.question('chocolate', 'Like chocolate?', {type: '{%= alias %}'});
enquirer.question('vanilla', 'Like vanilla?', {type: '{%= alias %}'});

enquirer
  .prompt(['chocolate', 'vanilla'])
  .then(function(answers) {
    console.log(answers)
  });