4 * A collection of common interactive command line user interfaces.
7 var inquirer = module.exports;
13 inquirer.prompts = {};
15 inquirer.Separator = require('./objects/separator');
18 BottomBar: require('./ui/bottom-bar'),
19 Prompt: require('./ui/prompt'),
23 * Create a new self-contained prompt module.
25 inquirer.createPromptModule = function (opt) {
26 var promptModule = function (questions, answers) {
29 ui = new inquirer.ui.Prompt(promptModule.prompts, opt);
31 return Promise.reject(error);
33 var promise = ui.run(questions, answers);
35 // Monkey patch the UI on the promise object so
36 // that it remains publicly accessible.
42 promptModule.prompts = {};
45 * Register a prompt type
46 * @param {String} name Prompt type name
47 * @param {Function} prompt Prompt constructor
51 promptModule.registerPrompt = function (name, prompt) {
52 promptModule.prompts[name] = prompt;
57 * Register the defaults provider prompts
60 promptModule.restoreDefaultPrompts = function () {
61 this.registerPrompt('list', require('./prompts/list'));
62 this.registerPrompt('input', require('./prompts/input'));
63 this.registerPrompt('number', require('./prompts/number'));
64 this.registerPrompt('confirm', require('./prompts/confirm'));
65 this.registerPrompt('rawlist', require('./prompts/rawlist'));
66 this.registerPrompt('expand', require('./prompts/expand'));
67 this.registerPrompt('checkbox', require('./prompts/checkbox'));
68 this.registerPrompt('password', require('./prompts/password'));
69 this.registerPrompt('editor', require('./prompts/editor'));
72 promptModule.restoreDefaultPrompts();
78 * Public CLI helper interface
79 * @param {Array|Object|Rx.Observable} questions - Questions settings array
80 * @param {Function} cb - Callback being passed the user answers
81 * @return {inquirer.ui.Prompt}
84 inquirer.prompt = inquirer.createPromptModule();
86 // Expose helper functions on the top level for easiest usage by common users
87 inquirer.registerPrompt = function (name, prompt) {
88 inquirer.prompt.registerPrompt(name, prompt);
91 inquirer.restoreDefaultPrompts = function () {
92 inquirer.prompt.restoreDefaultPrompts();