function drush_main

8.0.x preflight.inc drush_main()
6.x drush.php drush_main()
7.x drush.php drush_main()
3.x drush.php drush_main()
4.x drush.php drush_main()
5.x drush.php drush_main()
master preflight.inc 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 value

Whatever the given command returns.

File

./drush.php, line 33
drush is a PHP script implementing a command line shell for Drupal.

Code

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;
}