website/node_modules/inquirer/README.md

Inquirer.js

npm tests Coverage Status dependencies

A collection of common interactive command line user interfaces.

Table of Contents

  1. Documentation
    1. Installation
    2. Examples
    3. Methods
    4. Objects
    5. Questions
    6. Answers
    7. Separator
    8. Prompt Types
  2. User Interfaces and Layouts
    1. Reactive Interface
  3. Support
  4. News
  5. Contributing
  6. License
  7. Plugins

Goal and Philosophy

Inquirer Logo

Inquirer.js strives to be an easily embeddable and beautiful command line interface for Node.js (and perhaps the "CLI Xanadu").

Inquirer.js should ease the process of - providing error feedback - asking questions - parsing input - validating answers - managing hierarchical prompts

Note: Inquirer.js provides the user interface and the inquiry session flow. If you're searching for a full blown command line program utility, then check out commander, vorpal or args.

Documentation

Installation

npm install inquirer
var inquirer = require('inquirer');
inquirer.prompt([/* Pass your questions in here */]).then(function (answers) {
    // Use user feedback for... whatever!!
});

Examples (Run it and see it)

Check out the examples/ folder for code and interface examples.

node examples/pizza.js
node examples/checkbox.js
# etc...

Methods

inquirer.prompt(questions) -> promise

Launch the prompt interface (inquiry session)

inquirer.registerPrompt(name, prompt)

Register prompt plugins under name.

inquirer.createPromptModule() -> prompt function

Create a self contained inquirer module. If you don't want to affect other libraries that also rely on inquirer when you overwrite or add new prompt types.

var prompt = inquirer.createPromptModule();

prompt(questions).then(/* ... */);

Objects

Question

A question object is a hash containing question related values:

default, choices(if defined as functions), validate, filter and when functions can be called asynchronous. Either return a promise or use this.async() to get a callback you'll call with the final value.

{
  /* Preferred way: with promise */
  filter: function () {
    return new Promise(/* etc... */);
  },

  /* Legacy way: with this.async */
  validate: function (input) {
    // Declare function as asynchronous, and save the done callback
    var done = this.async();

    // Do async stuff
    setTimeout(function () {
      if (typeof input !== 'number') {
        // Pass the return value in the done callback
        done('You need to provide a number');
        return;
      }
      // Pass the return value in the done callback
      done(null, true);
    }, 3000);
  }
}

Answers

A key/value hash containing the client answers in each prompt.

Separator

A separator can be added to any choices array:

// In the question object
choices: [ "Choice A", new inquirer.Separator(), "choice B" ]

// Which'll be displayed this way
[?] What do you want to do?
 > Order a pizza
   Make a reservation
   --------
   Ask opening hours
   Talk to the receptionist

The constructor takes a facultative String value that'll be use as the separator. If omitted, the separator will be --------.

Separator instances have a property type equal to separator. This should allow tools façading Inquirer interface from detecting separator types in lists.

Prompt types

Note:: allowed options written inside square brackets ([]) are optional. Others are required.

List - {type: 'list'}

Take type, name, message, choices[, default, filter] properties. (Note that default must be the choice index in the array or a choice value)

List prompt

Raw List - {type: 'rawlist'}

Take type, name, message, choices[, default, filter] properties. (Note that default must the choice index in the array)

Raw list prompt

Expand - {type: 'expand'}

Take type, name, message, choices[, default] properties. (Note that default must be the choice index in the array. If default key not provided, then help will be used as default choice)

Note that the choices object will take an extra parameter called key for the expand prompt. This parameter must be a single (lowercased) character. The h option is added by the prompt and shouldn't be defined by the user.

See examples/expand.js for a running example.

Expand prompt closed Expand prompt expanded

Checkbox - {type: 'checkbox'}

Take type, name, message, choices[, filter, validate, default] properties. default is expected to be an Array of the checked choices value.

Choices marked as {checked: true} will be checked by default.

Choices whose property disabled is truthy will be unselectable. If disabled is a string, then the string will be outputted next to the disabled choice, otherwise it'll default to "Disabled". The disabled property can also be a synchronous function receiving the current answers as argument and returning a boolean or a string.

Checkbox prompt

Confirm - {type: 'confirm'}

Take type, name, message[, default] properties. default is expected to be a boolean if used.

Confirm prompt

Input - {type: 'input'}

Take type, name, message[, default, filter, validate] properties.

Input prompt

Password - {type: 'password'}

Take type, name, message[, default, filter, validate] properties.

Password prompt

Editor - {type: 'editor'}

Take type, name, message[, default, filter, validate] properties

Launches an instance of the users preferred editor on a temporary file. Once the user exits their editor, the contents of the temporary file are read in as the result. The editor to use is determined by reading the $VISUAL or $EDITOR environment variables. If neither of those are present, notepad (on Windows) or vim (Linux or Mac) is used.

User Interfaces and layouts

Along with the prompts, Inquirer offers some basic text UI.

Bottom Bar - inquirer.ui.BottomBar

This UI present a fixed text at the bottom of a free text zone. This is useful to keep a message to the bottom of the screen while outputting command outputs on the higher section.

var ui = new inquirer.ui.BottomBar();

// pipe a Stream to the log zone
outputStream.pipe(ui.log);

// Or simply write output
ui.log.write('something just happened.');
ui.log.write('Almost over, standby!');

// During processing, update the bottom bar content to display a loader
// or output a progress bar, etc
ui.updateBottomBar('new bottom bar content');

Reactive interface

Internally, Inquirer uses the JS reactive extension to handle events and async flows.

This mean you can take advantage of this feature to provide more advanced flows. For example, you can dynamically add questions to be asked:

var prompts = new Rx.Subject();
inquirer.prompt(prompts);

// At some point in the future, push new questions
prompts.onNext({ /* question... */ });
prompts.onNext({ /* question... */ });

// When you're done
prompts.onCompleted();

And using the return value process property, you can access more fine grained callbacks:

inquirer.prompt(prompts).ui.process.subscribe(
  onEachAnswer,
  onError,
  onComplete
);

Support (OS Terminals)

You should expect mostly good support for the CLI below. This does not mean we won't look at issues found on other command line - feel free to report any!

News on the march (Release notes)

Please refer to the Github releases section for the changelog

Contributing

Unit test Unit test are written in Mocha. Please add a unit test for every new feature or bug fix. npm test to run the test suite.

Documentation Add documentation for every API change. Feel free to send typo fixes and better docs!

We're looking to offer good support for multiple prompts and environments. If you want to help, we'd like to keep a list of testers for each terminal/OS so we can contact you and get feedback before release. Let us know if you want to be added to the list (just tweet to @vaxilart) or just add your name to the wiki

License

Copyright (c) 2016 Simon Boudrias (twitter: @vaxilart) Licensed under the MIT license.

Plugins

Prompts

autocomplete Presents a list of options as the user types, compatible with other packages such as fuzzy (for search) autocomplete prompt

datetime Customizable date/time selector using both number pad and arrow keys Datetime Prompt

inquirer-select-line Prompt for selecting index in array where add new element inquirer-select-line gif

command Simple prompt with command history and dynamic autocomplete

inquirer-chalk-pipe Prompt for input chalk-pipe style strings inquirer-chalk-pipe



JohnCoene/chirp documentation built on May 25, 2021, 6:33 p.m.