drush.php

  1. 8.0.x drush.php
  2. 6.x drush.php
  3. 7.x drush.php
  4. 3.x drush.php
  5. 4.x drush.php
  6. 5.x drush.php
  7. master lib/Drush.php
  8. master drush.php

drush is a PHP script implementing a command line shell for Drupal.

@requires PHP CLI 5.3.0, or newer.

Functions

Namesort descending Description
drush_main The main Drush function.

File

drush.php
View source
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * @file
  5. * drush is a PHP script implementing a command line shell for Drupal.
  6. *
  7. * @requires PHP CLI 5.3.0, or newer.
  8. */
  9. exit(drush_main());
  10. /**
  11. * The main Drush function.
  12. *
  13. * - Runs "early" option code, if set (see global options).
  14. * - Parses the command line arguments, configuration files and environment.
  15. * - Prepares and executes a Drupal bootstrap, if possible,
  16. * - Dispatches the given command.
  17. *
  18. * function_exists('drush_main') may be used by modules to detect whether
  19. * they are being called from Drush. See http://drupal.org/node/1181308
  20. * and http://drupal.org/node/827478
  21. *
  22. * @return mixed
  23. * Whatever the given command returns.
  24. */
  25. function drush_main() {
  26. // Load Drush core include files, and parse command line arguments.
  27. require dirname(__FILE__) . '/includes/preflight.inc';
  28. if (drush_preflight_prepare() === FALSE) {
  29. return(1);
  30. }
  31. // Start code coverage collection.
  32. if ($coverage_file = drush_get_option('drush-coverage', FALSE)) {
  33. drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
  34. xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
  35. register_shutdown_function('drush_coverage_shutdown');
  36. }
  37. // Load the global Drush configuration files, and global Drush commands.
  38. // Find the selected site based on --root, --uri or cwd
  39. // Preflight the selected site, and load any configuration and commandfiles associated with it.
  40. // Select and return the bootstrap class.
  41. $bootstrap = drush_preflight();
  42. // Reset our bootstrap phase to the beginning
  43. drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
  44. $return = '';
  45. if (!drush_get_error()) {
  46. if ($file = drush_get_option('early', FALSE)) {
  47. require_once $file;
  48. $function = 'drush_early_' . basename($file, '.inc');
  49. if (function_exists($function)) {
  50. if ($return = $function()) {
  51. // If the function returns FALSE, we continue and attempt to bootstrap
  52. // as normal. Otherwise, we exit early with the returned output.
  53. if ($return === TRUE) {
  54. $return = '';
  55. }
  56. }
  57. }
  58. }
  59. else {
  60. // Do any necessary preprocessing operations on the command,
  61. // perhaps handling immediately.
  62. $command_handled = drush_preflight_command_dispatch();
  63. if (!$command_handled) {
  64. $return = $bootstrap->bootstrap_and_dispatch();
  65. }
  66. }
  67. }
  68. // TODO: Get rid of global variable access here, and just trust
  69. // the bootstrap object returned from drush_preflight(). This will
  70. // require some adjustments to Drush bootstrapping.
  71. // See: https://github.com/drush-ops/drush/pull/1303
  72. if ($bootstrap = drush_get_bootstrap_object()) {
  73. $bootstrap->terminate();
  74. }
  75. drush_postflight();
  76. // How strict are we? If we are very strict, turn 'ok' into 'error'
  77. // if there are any warnings in the log.
  78. if (($return == 0) && (drush_get_option('strict') > 1) && drush_log_has_errors()) {
  79. $return = 1;
  80. }
  81. // After this point the drush_shutdown function will run,
  82. // exiting with the correct exit code.
  83. return $return;
  84. }