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 583
Functions used by drush to query the environment and setting the current configuration.


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.
  if (!($columns = getenv('COLUMNS'))) {
    exec('stty size 2>&1', $stty_output, $stty_status);
    if (!$stty_status) {
      $columns = preg_replace('/\d+\s(\d+)/', '$1', $stty_output[0], -1, $stty_count);
    // If stty failed, or we couldn't parse it's output, we assume 80 columns.
    if ($stty_status || !$stty_count) {
      $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());

  $drush_info = drush_read_drush_info();
  define('DRUSH_VERSION', $drush_info['drush_version']);
  $version_parts = explode('.', DRUSH_VERSION);
  define('DRUSH_MAJOR_VERSION', $version_parts[0]);
  define('DRUSH_MINOR_VERSION', $version_parts[1]);

  // prime the CWD cache

  /* Copy ETC_PREFIX and SHARE_PREFIX from environment variables if available.
   * This alters where we check for server-wide config and alias files.
   * Used by unit test suite to provide a clean environment.
  if (getenv('ETC_PREFIX')) {
    drush_set_context('ETC_PREFIX', getenv('ETC_PREFIX'));
  if (getenv('SHARE_PREFIX')) {
    drush_set_context('SHARE_PREFIX', getenv('SHARE_PREFIX'));

  drush_set_context('DOC_PREFIX', DRUSH_BASE_PATH);
  if (!file_exists(DRUSH_BASE_PATH . '/README.txt') && file_exists(drush_get_context('SHARE_PREFIX', '/usr') . '/share/doc/drush') . '/README.txt') {
    drush_set_context('DOC_PREFIX', drush_get_context('SHARE_PREFIX', '/usr') . '/share/doc/drush');

  // 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.
  // TODO: Note that this function will call drush_locate_root
  // (from within _drush_sitealias_find_record_for_local_site),
  // and drush_locate_root will be called again when bootstrapping
  // the drupal root below.  Is there a good way to refactor this
  // so that we do not need to search for the root twice?

  $backend = drush_set_context('DRUSH_BACKEND', drush_get_option(array('b', 'backend')));

  if ($backend) {
    // Load options passed as a JSON encoded string through STDIN.
    $stdin_options = _drush_backend_get_stdin();
    if (is_array($stdin_options)) {
      drush_set_context('stdin', $stdin_options);

  // Pipe implies quiet.
  $quiet = drush_set_context('DRUSH_QUIET', drush_get_option(array('q', 'quiet', 'p', 'pipe')));

  drush_set_context('DRUSH_PIPE', drush_get_option(array('p', 'pipe')));

  // When running in backend mode, all output is buffered, and returned
  // as a property of a JSON encoded associative array.
  if ($backend || $quiet) {