function _drush_backend_argument_string

8.0.x _drush_backend_argument_string($data, $os = NULL)
6.x _drush_backend_argument_string($data, $os = NULL)
7.x _drush_backend_argument_string($data, $os = NULL)
3.x _drush_backend_argument_string(&$data, $method = 'GET')
4.x _drush_backend_argument_string(&$data, $method = 'GET')
5.x _drush_backend_argument_string($data, $os = NULL)
master _drush_backend_argument_string($data, $os = NULL)

Map the options to a string containing all the possible arguments and options.


data: Optional. An array containing options to pass to the remote script. Array items with a numeric key are treated as optional arguments to the command. This parameter is a reference, as any options that have been represented as either an option, or an argument will be removed. This allows you to pass the left over options as a JSON encoded string, without duplicating data.

method: Optional. Defaults to 'GET'. If this parameter is set to 'POST', the $data array will be passed to the script being called as a JSON encoded string over the STDIN pipe of that process. This is preferable if you have to pass sensitive data such as passwords and the like. For any other value, the $data array will be collapsed down into a set of command line options to the script.

Return value

A properly formatted and escaped set of arguments and options to append to the drush.php shell command.

1 call to _drush_backend_argument_string()
_drush_backend_generate_command_sitealias in includes/
Generate a command to execute.


includes/, line 584
Drush backend API


function _drush_backend_argument_string(&$data, $method = 'GET') {
  // Named keys are options, numerically indexed keys are optional arguments.
  $args = array();
  $options = array();

  foreach ($data as $key => $value) {
    if (!is_array($value) && !is_object($value) && !is_null($value) && ($value != '')) {
      if (is_numeric($key)) {
        $args[$key] = $value;
      elseif (substr($key, 0, 1) != '#') {
        $options[$key] = $value;
  if (array_key_exists('backend', $data)) {

  $special = array('root', 'uri'); // These should be in the command line.
  $option_str = '';
  foreach ($options as $key => $value) {
    if (($method != 'POST') || (($method == 'POST') && in_array($key, $special))) {
      $option_str .= _drush_escape_option($key, $value);
      unset($data[$key]); // Remove items in the data array.

  return $option_str;