wishthis/node_modules/inquirer/lib/inquirer.js

94 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
'use strict';
/**
* Inquirer.js
* A collection of common interactive command line user interfaces.
*/
2022-04-07 07:06:43 +00:00
const inquirer = module.exports;
2022-01-21 08:28:41 +00:00
/**
* Client interfaces
*/
inquirer.prompts = {};
inquirer.Separator = require('./objects/separator');
inquirer.ui = {
BottomBar: require('./ui/bottom-bar'),
2022-04-07 07:06:43 +00:00
Prompt: require('./ui/prompt'),
2022-01-21 08:28:41 +00:00
};
/**
* Create a new self-contained prompt module.
*/
2022-04-07 07:06:43 +00:00
inquirer.createPromptModule = function (opt) {
const promptModule = function (questions, answers) {
let ui;
try {
ui = new inquirer.ui.Prompt(promptModule.prompts, opt);
} catch (error) {
return Promise.reject(error);
}
const promise = ui.run(questions, answers);
2022-01-21 08:28:41 +00:00
// Monkey patch the UI on the promise object so
// that it remains publicly accessible.
promise.ui = ui;
return promise;
};
promptModule.prompts = {};
/**
* Register a prompt type
* @param {String} name Prompt type name
* @param {Function} prompt Prompt constructor
* @return {inquirer}
*/
2022-04-07 07:06:43 +00:00
promptModule.registerPrompt = function (name, prompt) {
2022-01-21 08:28:41 +00:00
promptModule.prompts[name] = prompt;
return this;
};
/**
* Register the defaults provider prompts
*/
2022-04-07 07:06:43 +00:00
promptModule.restoreDefaultPrompts = function () {
2022-01-21 08:28:41 +00:00
this.registerPrompt('list', require('./prompts/list'));
this.registerPrompt('input', require('./prompts/input'));
this.registerPrompt('number', require('./prompts/number'));
this.registerPrompt('confirm', require('./prompts/confirm'));
this.registerPrompt('rawlist', require('./prompts/rawlist'));
this.registerPrompt('expand', require('./prompts/expand'));
this.registerPrompt('checkbox', require('./prompts/checkbox'));
this.registerPrompt('password', require('./prompts/password'));
this.registerPrompt('editor', require('./prompts/editor'));
};
promptModule.restoreDefaultPrompts();
return promptModule;
};
/**
* Public CLI helper interface
* @param {Array|Object|Rx.Observable} questions - Questions settings array
* @param {Function} cb - Callback being passed the user answers
* @return {inquirer.ui.Prompt}
*/
inquirer.prompt = inquirer.createPromptModule();
// Expose helper functions on the top level for easiest usage by common users
2022-04-07 07:06:43 +00:00
inquirer.registerPrompt = function (name, prompt) {
2022-01-21 08:28:41 +00:00
inquirer.prompt.registerPrompt(name, prompt);
};
2022-04-07 07:06:43 +00:00
inquirer.restoreDefaultPrompts = function () {
2022-01-21 08:28:41 +00:00
inquirer.prompt.restoreDefaultPrompts();
};