drush.api.php

  1. 8.0.x drush.api.php
  2. 6.x docs/drush.api.php
  3. 7.x drush.api.php
  4. 3.x drush.api.php
  5. 4.x docs/drush.api.php
  6. 5.x docs/drush.api.php
  7. master drush.api.php

Documentation of the Drush API.

All drush commands are invoked in a specific order, using drush-made hooks, very similar to the Drupal hook system. See drush_invoke() for the actual implementation.

For any command named "hook", the following hooks are called, in order:

1. drush_hook_COMMAND_validate() 2. drush_hook_pre_COMMAND() 3. drush_hook_COMMAND() 4. drush_hook_post_COMMAND()

For example, here are the hook opportunities for a mysite.drush.inc file that wants to hook into the `pm-download` command.

1. drush_mysite_pm_download_validate() 2. drush_mysite_pre_pm_download() 3. drush_mysite_pm_download() 4. drush_mysite_post_pm_download()

If any of those fails, the rollback mechanism is called. It will call, in reverse, all _rollback hooks. The mysite command file can implement the following rollback hooks:

1. drush_mysite_post_pm_download_rollback() 2. drush_mysite_pm_download_rollback() 3. drush_mysite_pre_pm_download_rollback() 4. drush_mysite_pm_download_validate_rollback()

Before any command is called, hook_drush_init() is also called. hook_drush_exit() is called at the very end of command invocation.

See also

includes/command.inc

hook_drush_init()

drush_hook_COMMAND_validate()

drush_hook_pre_COMMAND()

drush_hook_COMMAND()

drush_hook_post_COMMAND()

drush_hook_post_COMMAND_rollback()

drush_hook_COMMAND_rollback()

drush_hook_pre_COMMAND_rollback()

drush_hook_COMMAND_validate_rollback()

hook_drush_exit()

Functions

Namesort descending Description
drush_hook_COMMAND Implementation of the actual drush command.
drush_hook_COMMAND_validate Run before a specific command executes.
drush_hook_post_COMMAND Run after a specific command executes. Logging an error stops command execution.
drush_hook_pre_COMMAND Run before a specific command executes. Logging an error stops command execution.
hook_drush_exit Take action after any command is run.
hook_drush_init Take action before any command is run. Logging an error stops command execution.
hook_drush_pm_adjust_download_destination Adjust the location that a project should be downloaded to.
hook_drush_pm_post_download Take action after a project has been downloaded.
hook_pm_post_update Take action after a project has been updated.

File

drush.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Documentation of the Drush API.
  5. *
  6. * All drush commands are invoked in a specific order, using
  7. * drush-made hooks, very similar to the Drupal hook system. See drush_invoke()
  8. * for the actual implementation.
  9. *
  10. * For any command named "hook", the following hooks are called, in
  11. * order:
  12. *
  13. * 1. drush_hook_COMMAND_validate()
  14. * 2. drush_hook_pre_COMMAND()
  15. * 3. drush_hook_COMMAND()
  16. * 4. drush_hook_post_COMMAND()
  17. *
  18. * For example, here are the hook opportunities for a mysite.drush.inc file
  19. * that wants to hook into the `pm-download` command.
  20. *
  21. * 1. drush_mysite_pm_download_validate()
  22. * 2. drush_mysite_pre_pm_download()
  23. * 3. drush_mysite_pm_download()
  24. * 4. drush_mysite_post_pm_download()
  25. *
  26. * If any of those fails, the rollback mechanism is called. It will
  27. * call, in reverse, all _rollback hooks. The mysite command file can implement
  28. * the following rollback hooks:
  29. *
  30. * 1. drush_mysite_post_pm_download_rollback()
  31. * 2. drush_mysite_pm_download_rollback()
  32. * 3. drush_mysite_pre_pm_download_rollback()
  33. * 4. drush_mysite_pm_download_validate_rollback()
  34. *
  35. * Before any command is called, hook_drush_init() is also called.
  36. * hook_drush_exit() is called at the very end of command invocation.
  37. *
  38. * @see includes/command.inc
  39. *
  40. * @see hook_drush_init()
  41. * @see drush_hook_COMMAND_validate()
  42. * @see drush_hook_pre_COMMAND()
  43. * @see drush_hook_COMMAND()
  44. * @see drush_hook_post_COMMAND()
  45. * @see drush_hook_post_COMMAND_rollback()
  46. * @see drush_hook_COMMAND_rollback()
  47. * @see drush_hook_pre_COMMAND_rollback()
  48. * @see drush_hook_COMMAND_validate_rollback()
  49. * @see hook_drush_exit()
  50. */
  51. /**
  52. * @addtogroup hooks
  53. * @{
  54. */
  55. /**
  56. * Take action before any command is run. Logging an error stops command execution.
  57. */
  58. function hook_drush_init() {
  59. }
  60. /**
  61. * Run before a specific command executes.
  62. *
  63. * Logging an error stops command execution, and the rollback function (if any)
  64. * for each hook implementation is invoked.
  65. *
  66. * @see drush_hook_COMMAND_validate_rollback()
  67. */
  68. function drush_hook_COMMAND_validate() {
  69. }
  70. /**
  71. * Run before a specific command executes. Logging an error stops command execution.
  72. *
  73. * Logging an error stops command execution, and the rollback function (if any)
  74. * for each hook implementation is invoked, in addition to the
  75. * validate rollback.
  76. *
  77. * @see drush_hook_pre_COMMAND_rollback()
  78. * @see drush_hook_COMMAND_validate_rollback()
  79. */
  80. function drush_hook_pre_COMMAND() {
  81. }
  82. /**
  83. * Implementation of the actual drush command.
  84. *
  85. * This is where most of the stuff should happen.
  86. *
  87. * Logging an error stops command execution, and the rollback function (if any)
  88. * for each hook implementation is invoked, in addition to pre and
  89. * validate rollbacks.
  90. *
  91. * @see drush_hook_COMMAND_rollback()
  92. * @see drush_hook_pre_COMMAND_rollback()
  93. * @see drush_hook_COMMAND_validate_rollback()
  94. */
  95. function drush_hook_COMMAND() {
  96. }
  97. /**
  98. * Run after a specific command executes. Logging an error stops command execution.
  99. *
  100. * Logging an error stops command execution, and the rollback function (if any)
  101. * for each hook implementation is invoked, in addition to pre, normal
  102. * and validate rollbacks.
  103. *
  104. * @see drush_hook_post_COMMAND_rollback()
  105. * @see drush_hook_COMMAND_rollback()
  106. * @see drush_hook_pre_COMMAND_rollback()
  107. * @see drush_hook_COMMAND_validate_rollback()
  108. */
  109. function drush_hook_post_COMMAND() {
  110. }
  111. /**
  112. * Take action after any command is run.
  113. */
  114. function hook_drush_exit() {
  115. }
  116. /**
  117. * Take action after a project has been downloaded.
  118. */
  119. function hook_drush_pm_post_download($project, $release, $destination) {
  120. }
  121. /**
  122. * Take action after a project has been updated.
  123. */
  124. function hook_pm_post_update($release_name, $release_candidate_version, $project_parent_path) {
  125. }
  126. /**
  127. * Adjust the location that a project should be downloaded to.
  128. */
  129. function hook_drush_pm_adjust_download_destination(&$project, $release) {
  130. if ($some_condition) {
  131. $project['project_install_location'] = '/path/to/install/to/' . basename($project['full_project_path']);
  132. }
  133. }
  134. /**
  135. * @} End of "addtogroup hooks".
  136. */