forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drush.php
executable file
·85 lines (77 loc) · 2.55 KB
/
drush.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env php
<?php
/**
* @file
* drush is a PHP script implementing a command line shell for Drupal.
*
* @requires PHP CLI 5.3.0, or newer.
*/
require dirname(__FILE__) . '/includes/preflight.inc';
if (drush_preflight_prepare() === FALSE) {
exit(1);
}
exit(drush_main());
/**
* The main Drush function.
*
* - Runs "early" option code, if set (see global options).
* - Parses the command line arguments, configuration files and environment.
* - Prepares and executes a Drupal bootstrap, if possible,
* - Dispatches the given command.
*
* function_exists('drush_main') may be used by modules to detect whether
* they are being called from Drush. See http://drupal.org/node/1181308
* and http://drupal.org/node/827478
*
* @return mixed
* Whatever the given command returns.
*/
function drush_main() {
$return = '';
// Start code coverage collection.
if ($coverage_file = drush_get_option('drush-coverage', FALSE)) {
drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
register_shutdown_function('drush_coverage_shutdown');
}
/* Set up bootstrap object, so that
* - 'early' files can bootstrap when needed.
* - bootstrap constants are available.
*/
$bootstrap_class = drush_get_option('bootstrap_class', 'Drush\Boot\DrupalBoot');
$bootstrap = new $bootstrap_class;
drush_set_context('DRUSH_BOOTSTRAP_OBJECT', $bootstrap);
$bootstrap->preflight();
// Process initial global options such as --debug.
_drush_preflight_global_options();
$return = '';
drush_preflight();
if (!drush_get_error()) {
if ($file = drush_get_option('early', FALSE)) {
require_once $file;
$function = 'drush_early_' . basename($file, '.inc');
if (function_exists($function)) {
if ($return = $function()) {
// If the function returns FALSE, we continue and attempt to bootstrap
// as normal. Otherwise, we exit early with the returned output.
if ($return === TRUE) {
$return = '';
}
}
}
}
else {
// Do any necessary preprocessing operations on the command,
// perhaps handling immediately.
$command_handled = drush_preflight_command_dispatch();
if (!$command_handled) {
$bootstrap = drush_get_context('DRUSH_BOOTSTRAP_OBJECT');
$return = $bootstrap->bootstrap_and_dispatch();
}
}
}
drush_postflight();
// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
}