MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / prompt

Method prompt

packages/cli/lib/base-generator.js:297–346  ·  view source on GitHub ↗

* Override the base prompt to skip prompts with default answers * @param questions - One or more questions

(questions)

Source from the content-addressed store, hash-verified

295 * @param questions - One or more questions
296 */
297 async prompt(questions) {
298 // Normalize the questions to be an array
299 if (!Array.isArray(questions)) {
300 questions = [questions];
301 }
302 if (!this.options['yes']) {
303 if (!process.stdin.isTTY) {
304 const msg =
305 'The stdin is not a terminal. No prompt is allowed. ' +
306 'Use --config to provide answers to required prompts and ' +
307 '--yes to skip optional prompts with default answers';
308 this.log(chalk.red(msg));
309 this.exit(new Error(msg));
310 return;
311 }
312 // Non-express mode, continue to prompt
313 debug('Questions', questions);
314 const answers = await super.prompt(questions);
315 debug('Answers', answers);
316 return answers;
317 }
318
319 const answers = Object.assign({}, this.options);
320
321 for (const q of questions) {
322 let when = q.when;
323 if (typeof when === 'function') {
324 when = await q.when(answers);
325 }
326 if (when === false) continue;
327 if (this._isQuestionOptional(q)) {
328 const answer = await this._getDefaultAnswer(q, answers);
329 debug('%s: %j', q.name, answer);
330 answers[q.name] = answer;
331 } else {
332 if (!process.stdin.isTTY) {
333 const msg =
334 'The stdin is not a terminal. No prompt is allowed. ' +
335 `(While resolving a required prompt ${JSON.stringify(q.name)}.)`;
336 this.log(chalk.red(msg));
337 this.exit(new Error(msg));
338 return;
339 }
340 // Only prompt for non-skipped questions
341 const props = await super.prompt([q]);
342 Object.assign(answers, props);
343 }
344 }
345 return answers;
346 }
347
348 /**
349 * Override the usage text by replacing `yo loopback4:` with `lb4 `.

Callers 15

promptArtifactNameMethod · 0.80
promptProjectNameMethod · 0.80
promptProjectDirMethod · 0.80
promptOptionsMethod · 0.80
promptYarnInstallMethod · 0.80
checkLoopBackProjectFunction · 0.80
promptExampleNameMethod · 0.80
promptModelsMethod · 0.80
promptArtifactTypeMethod · 0.80
promptOwnerAndLicenseMethod · 0.80
updateLicenseMethod · 0.80

Calls 4

exitMethod · 0.95
_isQuestionOptionalMethod · 0.95
_getDefaultAnswerMethod · 0.95
logMethod · 0.65

Tested by

no test coverage detected