function _drush_bootstrap_drush

6.x _drush_bootstrap_drush()
3.x _drush_bootstrap_drush()
4.x _drush_bootstrap_drush()
5.x _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/
Helper function listing phases.


includes/, line 429
Drush bootstrapping 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.
  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()) {
      $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

  // Set up base environment for system-wide file locations.

  // Load a drushrc.php file in the drush.php's directory.

  // Load a drushrc.php file in the $ETC_PREFIX/etc/drush directory.

  // Load a drushrc.php file at ~/.drushrc.php.

  // Load a drushrc.php file in the ~/.drush directory.

  // Load a custom config specified with the --config option.

  // 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.

  // Check to see if we 'use'd a site alias with site-set

  // If an alias was not created by drush_sitealias_check_arg()
  // or drush_sitealias_check_site_env(), make one now.

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

  // Similarly, load the Drupal site configuration options upfront.

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

  // 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.  This is also the place
  // where we will find @self, if it was created via
  // drush_sitealias_create_self_alias().
  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.