function drush_process_bootstrap_to_first_arg

8.0.x command.inc drush_process_bootstrap_to_first_arg(&$arguments)
6.x command.inc drush_process_bootstrap_to_first_arg(&$arguments)
7.x command.inc drush_process_bootstrap_to_first_arg(&$arguments)
4.x command.inc drush_process_bootstrap_to_first_arg(&$arguments)
5.x command.inc drush_process_bootstrap_to_first_arg(&$arguments)
master command.inc drush_process_bootstrap_to_first_arg(&$arguments)

Process the --bootstrap-to-first-arg option, if it is present.

This option checks to see if the first user-provided argument is an alias or site specification; if it is, it will be shifted into the first argument position, where it will specify the site to bootstrap. The result of this is that if your shebang line looks like this:

#!/path/to/drush --bootstrap-to-first-arg php-script

Then when you run that script, you can optionally provide an alias such as @dev as the first argument (e.g. $ ./mydrushscript.php @dev scriptarg1 scriptarg2). Since this is the behavior that one would usually want, it is default behavior for a canonical script. That is, a script with a simple shebang line, like so:

#!/path/to/drush

will implicitly have "--bootstrap-to-first-arg" and "php-script" prepended, and will therefore behave exactly like the first example. To write a script that does not use --bootstrap-to-first-arg, then the drush command or at least one flag must be explicitly included, like so:

#!/path/to/drush php-script

1 call to drush_process_bootstrap_to_first_arg()
drush_parse_args in includes/command.inc
Parse console arguments.

File

includes/command.inc, line 975
The drush command engine.

Code

function drush_process_bootstrap_to_first_arg(&$arguments) {
  if (drush_get_option('bootstrap-to-first-arg', FALSE)) {
    $shift_alias_pos = 1 + (drush_get_context('DRUSH_SHEBANG_SCRIPT') === TRUE);
    if (count($arguments) >= $shift_alias_pos) {
      $shifted_alias = $arguments[$shift_alias_pos];
      $alias_record = drush_sitealias_get_record($shifted_alias);
      if (!empty($alias_record)) {
        // Move the alias we shifted from its current position
        // in the argument list to the front of the list
        array_splice($arguments, $shift_alias_pos, 1);
        array_unshift($arguments, $shifted_alias);
      }
    }
  }
}