I noticed that drush_backend_invoke() assumes that the first word in $args is a command and the rest of the words are arguments. This is not true for many commands like 'sql query'. This is typically not a problem - the command gets invoked fine. Thus I set this to minor.

Note that the autocomplete folks really begged us to use one word commands like 'sql:query' or 'sql-query' instead of 'sql query'. So the right answer here might be to change many command names to always be prefixed. This might be more tolerable now that we have command aliases.

Comments

adrian’s picture

drush_backend_invoke assumes

1) $command is a string
2) $args is an array, with OPTIONS as string indexed items and ARGUMENTS as numerically indexed items.

so in the command

drush.php mycommand here arg1 arg2 --option1=option1 --option2=option2

you would have

drush_backend_invoke('mycommand here', array( 'arg1', 'arg2', 'option1'=> 'option1', 'option2' => 'option2'));

hence :

drush.php $command $numeric_indexed_items $string_indexed_items
adrian’s picture

also, see drush_backend_invoke_args()

greg.1.anderson’s picture

There is this function:

function drush_backend_invoke($command, $data = array(), $method = 'GET', $integrate = TRUE, $drush_path = NULL, $hostname = NULL, $username = NULL) {
  $args = explode(" ", $command);
  $command = array_shift($args);
  return drush_backend_invoke_args($command, $args, $data, $method, $integrate, $drush_path, $hostname, $username);
}

The $command = array_shift($args); assumes that the first word is the command, and the second and subsequent words are args. _drush_backend_generate_command puts everything back together correctly again, so it's not a huge problem, but please also see the discussion in #658420: helper functions for drush_backend_invoke().

Perhaps the best solution would be to have drush_backend_invoke_args($command, $args, ...) call through to drush_backend_invoke_args($args, ...) after first exploding $command and merging it with $args. In this case, then _drush_backend_generate_command also would take only $args.

If you were calling backend invoke from code, you'd do it as you suggest in #1, but if you were re-dispatching using the $args list that were passed in on the command line you could instead do something like this:

/*
* Spawn a subshell which runs the same command we are currently running.
*/
function drush_migrate_backend_invoke() {
  $args = drush_get_arguments();
  $options = drush_migrate_get_options();
  drush_backend_invoke_args($args, $options);
}

(n.b. the two polymorphic drush_backend_invoke_args probably need different names due to the default arguments; I apologize for any confusion caused by giving them the same name here.)

In this case, it is neither assumed nor specified how many elements of $args are the command and how many are the other arguments.

moshe weitzman’s picture

Status: Active » Closed (works as designed)

command must now be single word. spaces in commands are deprecated. nothing to do here. if i am wrong, please reopen.