How do you prompt the user for input in Yeoman?

Prepare for the Yeoman (YN) Test. Use flashcards and multiple-choice questions, all with hints and explanations, to get ready for your upcoming exam. Enhance your learning experience!

Multiple Choice

How do you prompt the user for input in Yeoman?

Explanation:
Prompting in Yeoman uses the built-in prompt system provided by the Generator base class. You give it an array of prompt objects, and each prompt describes what to ask and how to store the answer. Each prompt includes: - type: what kind of input (for example, 'input' for free text, 'confirm' for yes/no, 'list' for selecting from options) - name: the key under which the answer will be stored - message: the question shown to the user - default: a default value to show if the user doesn’t type anything When you run this.prompt with that array, Yeoman (via Inquirer) presents the questions to the user and returns a promise with an answers object where each property matches the corresponding name. You can then save those answers for later steps, often into this.props or this.config. This approach is standard and simple: it centralizes all prompts in one place, leverages the existing Yeoman flow, and guarantees a consistent user experience. Other options like a non-existent this.ask, or pulling prompts from a separate library, aren’t how Yeoman handles prompting, and this.input isn’t a Yeoman API.

Prompting in Yeoman uses the built-in prompt system provided by the Generator base class. You give it an array of prompt objects, and each prompt describes what to ask and how to store the answer. Each prompt includes:

  • type: what kind of input (for example, 'input' for free text, 'confirm' for yes/no, 'list' for selecting from options)
  • name: the key under which the answer will be stored

  • message: the question shown to the user

  • default: a default value to show if the user doesn’t type anything

When you run this.prompt with that array, Yeoman (via Inquirer) presents the questions to the user and returns a promise with an answers object where each property matches the corresponding name. You can then save those answers for later steps, often into this.props or this.config.

This approach is standard and simple: it centralizes all prompts in one place, leverages the existing Yeoman flow, and guarantees a consistent user experience. Other options like a non-existent this.ask, or pulling prompts from a separate library, aren’t how Yeoman handles prompting, and this.input isn’t a Yeoman API.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy