* Override the base prompt to skip prompts with default answers * @param questions - One or more questions
(questions)
| 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 `. |
no test coverage detected