Example #1
0
/**
 * 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);
    if (!drush_get_error()) {
        // Do any necessary preprocessing operations on the command,
        // perhaps handling immediately.
        $command_handled = drush_preflight_command_dispatch();
        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;
}
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     drush_bootstrap_finish();
 }