function _drush_bootstrap_drush

6.x bootstrap.inc _drush_bootstrap_drush()
3.x environment.inc _drush_bootstrap_drush()
4.x environment.inc _drush_bootstrap_drush()
5.x bootstrap.inc _drush_bootstrap_drush()

Initial Drush bootstrap phase.

During the initialization of Drush, this is the first step where all we are aware of is Drush itself.

In this step we will register the shutdown function, parse the command line arguments and store them in their related contexts.

Configuration files (drushrc.php) that are a) Specified on the command line b) Stored in the root directory of drush.php c) Stored in the home directory of the system user.

Additionally the DRUSH_QUIET and DRUSH_BACKEND contexts, will be evaluated now, as they need to be set very early in the execution flow to be able to take affect/

1 string reference to '_drush_bootstrap_drush'
_drush_bootstrap_phases in includes/bootstrap.inc
Helper function listing phases.

File

includes/bootstrap.inc, line 429
Drush bootstrapping code.

Code

function _drush_bootstrap_drush() {
  // Create an alias '@none' to represent no Drupal site
  _drush_sitealias_cache_alias('none', array('root' => '', 'uri' => ''));

  // Set the terminal width, used for wrapping table output.
  // Normally this is exported using tput in the drush script.
  // If this is not present we do an additional check using stty here.
  // On Windows in CMD and PowerShell is this exported using mode con.
  // PHP version prior to 5.3.0 is not supporting this, they always
  // return 80 columns
  if (!($columns = getenv('COLUMNS'))) {
    // Trying to export the columns using stty.
    exec('stty size 2>&1', $columns_output, $columns_status);
    if (!$columns_status) {
      $columns = preg_replace('/\d+\s(\d+)/', '$1', $columns_output[0], -1, $columns_count);
    }

    // If stty fails and Drush us running on Windows are we trying with mode con.
    if (($columns_status || !$columns_count) && drush_is_windows() && version_compare(phpversion(), '5.3.0') > -1) {
      $columns_output = array();
      exec('mode con', $columns_output, $columns_status);
      if (!$columns_status && is_array($columns_output)) {
        $columns = (int) preg_replace('/\D/', '', $columns_output[4], -1, $columns_count);
      }
      else {
        drush_log(dt('Drush could not detect the console window width. Set a Windows Environment Variable of COLUMNS to the desired width.'), 'warning');
      }
    }

    // Failling back to default columns value
    if (empty($columns)) {
      $columns = 80;
    }
  }
  // If a caller wants to reserve some room to add additional
  // information to the drush output via post-processing, the
  // --reserve-margin flag can be used to declare how much
  // space to leave out.  This only affects drush functions
  // such as drush_print_table that wrap the output.
  $columns -= drush_get_option('reserve-margin', 0);
  drush_set_context('DRUSH_COLUMNS', $columns);

  // Statically define a way to call drush again.
  define('DRUSH_COMMAND', drush_find_drush());

  // prime the CWD cache
  drush_cwd();

  // Set up base environment for system-wide file locations.
  _drush_bootstrap_base_environment();

  // Load a drushrc.php file in the drush.php's directory.
  drush_load_config('drush');

  // Load a drushrc.php file in the $ETC_PREFIX/etc/drush directory.
  drush_load_config('system');

  // Load a drushrc.php file at ~/.drushrc.php.
  drush_load_config('user');

  // Load a drushrc.php file in the ~/.drush directory.
  drush_load_config('home.drush');

  // Load a custom config specified with the --config option.
  drush_load_config('custom');

  // Process the site alias that specifies which instance
  // of drush (local or remote) this command will operate on.
  // We must do this after we load our config files (so that
  // site aliases are available), but before the rest
  // of the drush and drupal root bootstrap phases are
  // done, since site aliases may set option values that
  // affect these phases.
  drush_sitealias_check_arg();

  // Check to see if we 'use'd a site alias with site-set
  drush_sitealias_check_site_env();

  // Load the config options from Drupal's /drush and sites/all/drush directories,
  // even prior to bootstrapping the root.
  drush_load_config('drupal');

  // Similarly, load the Drupal site configuration options upfront.
  drush_load_config('site');

  // If applicable swaps in shell alias value (or executes it).
  drush_shell_alias_replace();

  // If drush_load_config defined a site alias that did not
  // exist before, then sitealias check arg might now match
  // against one of those aliases.
  if ((drush_sitealias_check_arg() === TRUE) || (drush_sitealias_check_site_env() === TRUE)) {
    $remote_host = drush_get_option('remote-host');
    if (!isset($remote_host)) {
      // Load the config files for the "new" site.
      drush_load_config('drupal');
      drush_load_config('site');
    }
  }

  _drush_bootstrap_global_options();
}