forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrush.php
executable file
·127 lines (112 loc) · 4.05 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env php
<?php
/**
* @file
* drush is a PHP script implementing a command line shell for Drupal.
*
* @requires PHP CLI 5.2.0, or newer.
*/
require(dirname(__FILE__) . '/includes/bootstrap.inc');
drush_bootstrap_prepare();
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
* Whatever the given command returns.
*/
function drush_main() {
$return = '';
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 = '';
}
drush_bootstrap_finish();
return $return;
}
}
}
// Process initial global options such as --debug.
_drush_bootstrap_global_options();
$return = '';
drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUSH);
// Process a remote command if 'remote-host' option is set.
$command_handled = drush_remote_command();
if (!$command_handled) {
$return = _drush_bootstrap_and_dispatch();
}
drush_bootstrap_finish();
// After this point the drush_shutdown function will run,
// exiting with the correct exit code.
return $return;
}
function _drush_bootstrap_and_dispatch() {
$phases = _drush_bootstrap_phases(FALSE, TRUE);
$return = '';
$command_found = FALSE;
_drush_bootstrap_output_prepare();
foreach ($phases as $phase) {
if (drush_bootstrap_to_phase($phase)) {
$command = drush_parse_command();
if (is_array($command)) {
$bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']);
drush_enforce_requirement_bootstrap_phase($command);
drush_enforce_requirement_core($command);
drush_enforce_requirement_drupal_dependencies($command);
drush_enforce_requirement_drush_dependencies($command);
if ($bootstrap_result && empty($command['bootstrap_errors'])) {
drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), 'bootstrap');
$command_found = TRUE;
// Dispatch the command(s).
$return = drush_dispatch($command);
// prevent a '1' at the end of the output
if ($return === TRUE) {
$return = '';
}
if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) {
drush_print_timers();
}
drush_log(dt('Peak memory usage was !peak', array('!peak' => drush_format_size(memory_get_peak_usage()))), 'memory');
break;
}
}
}
else {
break;
}
}
if (!$command_found) {
// If we reach this point, we have not found either a valid or matching command.
$args = implode(' ', drush_get_arguments());
if (isset($command) && is_array($command)) {
foreach ($command['bootstrap_errors'] as $key => $error) {
drush_set_error($key, $error);
}
drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args)));
}
elseif (!empty($args)) {
drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The drush command '!args' could not be found.", array('!args' => $args)));
}
// Set errors that ocurred in the bootstrap phases.
$errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
foreach ($errors as $code => $message) {
drush_set_error($code, $message);
}
}
return $return;
}