2

I am a newbie into Drupal.
I recently learned to create custom Drush command inside a custom module.

I am wondering if I can write a custom drush command and its definition without any module or outside module. for eg. If I have no custom module in my drupal project.

This custom command is available for execution only if my module is enabled. Can I write a drush command which is completely module independent?

Is it possible?

4

You might be interested in the drushify project, which will create a Drush commandfile for you, from a template. You can give it the name of a module, and run it from a Drupal site to make a Drush command for a module, or just give it an arbitrary name and run it from outside any Drupal site, and it will create a global Drush command.

From there, you only need to go through and fill in the parts of the template that it made for you. You may delete any of the optional hooks that you don't need -- which is usually most of them.

3

No .module or .info file is needed. The required steps for creating a command:

  1. Create a command file called COMMANDFILE.drush.inc
  2. Implement the function COMMANDFILE_drush_command()
  3. Implement the functions that your commands will call. These will usually be named drush_COMMANDFILE_COMMANDNAME().

Drush searches for commandfiles in the following locations:

  • The "/path/to/drush/commands" folder.
  • Folders listed in the 'include' option (see drush topic docs-configuration).
  • The system-wide drush commands folder, e.g. /usr/share/drush/commands
  • The ".drush" folder in the user's HOME folder.
  • /drush and /sites/all/drush in the current Drupal installation
  • All enabled modules in the current Drupal installation

Some additional documentation authoring custom commands - http://www.drush.org/en/master/commands/

2

Yes, you can place any *.drush.inc file in your ~/.drush dir to make Drush pickup on it. Checkout the drush_commandfile_list() docs for all the locations that Drush looks for command files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.