Skip to content

Latest commit

 

History

History
96 lines (80 loc) · 1.68 KB

.verb.md

File metadata and controls

96 lines (80 loc) · 1.68 KB

Install

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

Example usage

const List = require('{%= name %}');
const list = new List({
  name: 'order',
  message: 'What would you like to order?',
  // choices may be defined as an array or a function that returns an array
  choices: [
    'Coke',
    'Diet Coke',
    'Cherry Coke',
    {name: 'Sprite', disabled: 'Temporarily unavailable'},
    'Water'
  ]
});

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

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

Enquirer usage

Register the prompt as an [enquirer][] plugin:

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

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

Enquirer examples

Enquirer supports both declarative, inquirer-style questions, and an expressive format, using the .question method:

Declarative

const questions = [
  {
    type: 'list',
    name: 'order',
    message: 'What would you like to order?',
    choices: [
      'Coke',
      'Diet Coke',
      'Cherry Coke',
      {name: 'Sprite', disabled: 'Temporarily unavailable'},
      'Water'
    ]
  }
];

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

Expressive

enquirer.question('order', 'What would you like to order?', {
  type: 'list',
  choices: [
    'Coke',
    'Diet Coke',
    'Cherry Coke',
    {name: 'Sprite', disabled: 'Temporarily unavailable'},
    'Water'
  ]
});

enquirer.ask(['order'])
  .then(function(answers) {
    console.log(answers);
  })
  .catch(function(err) {
    console.log(err);
  });