source: trip-planner-front/node_modules/inquirer/lib/inquirer.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[6a3a178]1'use strict';
2/**
3 * Inquirer.js
4 * A collection of common interactive command line user interfaces.
5 */
6
7const inquirer = module.exports;
8
9/**
10 * Client interfaces
11 */
12
13inquirer.prompts = {};
14
15inquirer.Separator = require('./objects/separator');
16
17inquirer.ui = {
18 BottomBar: require('./ui/bottom-bar'),
19 Prompt: require('./ui/prompt'),
20};
21
22/**
23 * Create a new self-contained prompt module.
24 */
25inquirer.createPromptModule = function (opt) {
26 const promptModule = function (questions, answers) {
27 let ui;
28 try {
29 ui = new inquirer.ui.Prompt(promptModule.prompts, opt);
30 } catch (error) {
31 return Promise.reject(error);
32 }
33 const promise = ui.run(questions, answers);
34
35 // Monkey patch the UI on the promise object so
36 // that it remains publicly accessible.
37 promise.ui = ui;
38
39 return promise;
40 };
41
42 promptModule.prompts = {};
43
44 /**
45 * Register a prompt type
46 * @param {String} name Prompt type name
47 * @param {Function} prompt Prompt constructor
48 * @return {inquirer}
49 */
50
51 promptModule.registerPrompt = function (name, prompt) {
52 promptModule.prompts[name] = prompt;
53 return this;
54 };
55
56 /**
57 * Register the defaults provider prompts
58 */
59
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'));
70 };
71
72 promptModule.restoreDefaultPrompts();
73
74 return promptModule;
75};
76
77/**
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}
82 */
83
84inquirer.prompt = inquirer.createPromptModule();
85
86// Expose helper functions on the top level for easiest usage by common users
87inquirer.registerPrompt = function (name, prompt) {
88 inquirer.prompt.registerPrompt(name, prompt);
89};
90
91inquirer.restoreDefaultPrompts = function () {
92 inquirer.prompt.restoreDefaultPrompts();
93};
Note: See TracBrowser for help on using the repository browser.