What is a common pattern to create a custom CLI command for a generator?

Study for the Yeoman (YN) Test. Enhance your knowledge with multiple-choice questions, hints, and explanations. Prepare effectively for your exam!

Multiple Choice

What is a common pattern to create a custom CLI command for a generator?

Explanation:
Defining CLI options inside the generator and exposing usage through the Yeoman command’s --help is the standard way to add a custom CLI command for a generator. You declare flags with this.option(...) in your generator, specifying the type, description, and defaults. Yeoman then automatically builds the help output, so running yo <namespace> --help shows all the available options and what they do. Inside the generator you read the chosen values via this.options.<name> to steer the generator’s behavior, such as enabling features, choosing templates, or skipping prompts. This approach keeps the CLI intuitive and self-documenting. The other choices don’t fit because a GUI isn’t a CLI, installing a separate CLI tool adds unnecessary complexity, and embedding help in code comments doesn’t provide actionable runtime options or automatic help.

Defining CLI options inside the generator and exposing usage through the Yeoman command’s --help is the standard way to add a custom CLI command for a generator. You declare flags with this.option(...) in your generator, specifying the type, description, and defaults. Yeoman then automatically builds the help output, so running yo --help shows all the available options and what they do. Inside the generator you read the chosen values via this.options. to steer the generator’s behavior, such as enabling features, choosing templates, or skipping prompts. This approach keeps the CLI intuitive and self-documenting.

The other choices don’t fit because a GUI isn’t a CLI, installing a separate CLI tool adds unnecessary complexity, and embedding help in code comments doesn’t provide actionable runtime options or automatic help.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy