Generators jump start your coding by building all the boring boilerplate code for you. After running a drush generate [foo] command, you have a guide for where to insert your custom logic.

Drush's generators reuse classes provided by the excellent Drupal Code Generator project. See its Commands directory for inspiration.

Writing Custom Generators

Drupal modules may supply their own Generators, just like they can supply Commands.

See Woot module, which Drush uses for testing. Specifically,

  1. Write a class similar to ExampleGenerator. Implement your custom logic in the interact() method. Typically this class is placed in the src/Generators directory.
  2. Add your class to your module's drush.services.yml file (example). Use the tag drush.generator instead of drush.command.
  3. Perform a drush cache-rebuild to compile your drush.services.yml changes into the Drupal container.