function drush_complete_process_argv

8.0.x complete.inc drush_complete_process_argv()
6.x complete.inc drush_complete_process_argv()
7.x complete.inc drush_complete_process_argv()
5.x complete.inc drush_complete_process_argv()
master complete.inc drush_complete_process_argv()

This function resets the raw arguments so that Drush can parse the command as if it was run directly. The shell complete command passes the full command line as an argument, and the --early and --complete-debug options have to come before that, and the "drush" bash script will add a --php option on the end, so we end up with something like this:

/path/to/drush.php --early=includes/complete.inc [--complete-debug] drush [@alias] [command]... --php=/usr/bin/php

Note that "drush" occurs twice, and also that the second occurrence could be an alias, so we can't easily use it as to detect the start of the actual command. Hence our approach is to remove the initial "drush" and then any options directly following that - what remains is then the command we need to complete - i.e.:

drush [@alias] [command]...

Note that if completion is initiated following a space an empty argument is added to argv. So in that case argv looks something like this: array ( '0' => '/path/to/drush.php', '1' => '--early=includes/complete.inc', '2' => 'drush', '3' => 'topic', '4' => '', '5' => '--php=/usr/bin/php', );

Return value

$args Array of arguments (argv), excluding the initial command and options associated with the complete call. array ( '0' => 'drush', '1' => 'topic', '2' => '', );

1 call to drush_complete_process_argv()
drush_early_complete in includes/complete.inc
Produce autocomplete output.

File

includes/complete.inc, line 230
Provide completion output for shells.

Code

function drush_complete_process_argv() {
  $argv = drush_get_context('argv');
  // Remove the first argument, which will be the "drush" command.
  array_shift($argv);
  while (substr($arg = array_shift($argv), 0, 2) == '--') {
    // We remove all options, until we get to a non option, which
    // marks the start of the actual command we are trying to complete.
  }
  // Replace the initial argument.
  array_unshift($argv, $arg);
  // Remove the --php option at the end if exists (added by the "drush" shell
  // script that is called when completion is requested).
  if (substr(end($argv), 0, 6) == '--php=') {
    array_pop($argv);
  }
  drush_set_context('argv', $argv);
  drush_set_command(NULL);
  // Reparse arguments, site alias, and command.
  drush_parse_args();
  // Ensure the base environment is configured, so tests look in the correct
  // places.
  _drush_preflight_base_environment();
  // Check for and record any site alias.
  drush_sitealias_check_arg();
  drush_sitealias_check_site_env();
  // We might have just changed our root--run drush_select_bootstrap_class() again.
  $bootstrap = drush_select_bootstrap_class();

  // Return the new argv for easy reference.
  return $argv;
}