function _drush_should_remove_command_arg

8.0.x _drush_should_remove_command_arg($arg, $removal_list)
6.x _drush_should_remove_command_arg($arg, $removal_list)
7.x _drush_should_remove_command_arg($arg, $removal_list)
5.x _drush_should_remove_command_arg($arg, $removal_list)
master _drush_should_remove_command_arg($arg, $removal_list)

Determine whether or not an argument should be removed from the DRUSH_COMMAND_ARGS context. This method is used when a Drush command has set the 'strict-option-handling' flag indicating that it will pass through all commandline arguments and any additional options (not known to Drush) to some shell command.

Take as an example the following call to core-rsync:

drush --yes core-rsync -v -az --exclude-paths='.git:.svn' local-files/ @site:%files

In this instance:

--yes is a global Drush option

-v is an rsync option. It will make rsync run in verbose mode, but will not make Drush run in verbose mode due to the fact that core-rsync sets the 'strict-option-handling' flag.

--exclude-paths is a local Drush option. It will be converted by Drush into --exclude='.git' and --exclude='.svn', and then passed on to the rsync command.

The parameter $arg passed to this function is one of the elements of DRUSH_COMMAND_ARGS. It will have values such as: -v -az --exclude-paths='.git:.svn' local-files/ @site:%files

Our job in this function is to determine if $arg should be removed by virtue of appearing in $removal_list. $removal_list is an array that will contain values such as 'exclude-paths'. Both the key and the value of $removal_list is the same.

Related topics

1 call to _drush_should_remove_command_arg()
drush_preflight_command_dispatch in includes/
Handle any command preprocessing that may need to be done, including potentially redispatching the command immediately (e.g. for remote commands).


includes/, line 1264
The drush API implementation and helpers.


function _drush_should_remove_command_arg($arg, $removal_list) {
  foreach ($removal_list as $candidate) {
    if (($arg == "-$candidate") || ($arg == "--$candidate") || (substr($arg, 0, strlen($candidate) + 3) == "--$candidate=")) {
      return TRUE;
  return FALSE;