I either forgot or never knew that option validation only applies to local drush calls, and not --backend calls. That strikes me as suboptimal. Would it be hard to remove this restriction? See http://api.drush.org/api/drush/includes%21command.inc/function/_drush_ve.... Maybe we could remove the restriction and add a --strict=0 to any backend call that had to pass along unknown options for some reason.
Assigning to Greg for an initial discussion.
Comments
Comment #1
greg.1.anderson commentedThe reason that option verification is skipped here is that it would cause problems to attempt to validate the cli options when programaticly invoking a function, as existing code often unions together multiple unrelated options when calling subcommands.
drush @remote foocould remotely do cli option verification, though; the "don't validate me" net was cast too wide. I'll find a good way to insure that existing programitic calls remain unvalidated when we add validation to user-initiated remote calls.Comment #2
moshe weitzman commentedI think the caller could add --strict=0 when we think we are passing along merged options. That way we can stop treating backend requests as special. I'd love to have this for Drush6, but isn't a blocker.
Comment #3
greg.1.anderson commentedSo busy now, can't do a patch, but I can review. Sounds like a good idea.
Comment #4
moshe weitzman commentedI committed this feature in 27f2b1547be6cef3c2dc01d41f95341836ee3ae5, since it turned out to be quite simple. I made the changes listed below. The original issue which added option validation is #663290: Better feedback with bad arguments or options.
Comment #5
greg.1.anderson commentedThere are two minor problems here.
1. If the user defines an arbitrary option in a path alias, it is passed on as an option for all commands.
Example:
In this instance, drush will pass --project-type=live to all remote commands, causing them to fail.
Workaround: rename 'project-type' to '#project-type', or add 'strict' => 0 to any alias that uses this feature.
The advantage of this feature is that it allows you to pass an option to a remote machine that might be tested in a custom drush command init hook. I don't use this feature, and perhaps we could remove it (or just document the workarounds). Another option would be to create a new global option that could be used by backend invoke to list the "extra" options (e.g. added in aliases), so that they could be ignored on the other end. It might be hard to figure out which options to ignore; perhaps listing all of the options that came from the command line would be easier. If this option list existed, then only options thus named would be tested for validity.
2. The dump-dir path alias is also passed along as an option to remote commands.
Example:
Only 'dump-dir' is passed along; 'dump2-dir' or 'dump-dir2' or most any other path alias is not passed along as an option. Seems this behavior might have something to do with sql-sync, but I don't remember why this is happening, and did not find the responsible code after a cursory examination.
The workaround is to define 'strict' => 0 in any alias that defines the dump-dir.
Comment #6
moshe weitzman commented1. Another solution is to add a command file that alters in the new expected options. I think these 3 workaround are enough.
2. I'll trace this and see what us going on.
Comment #7
moshe weitzman commentedComment #8
ergonlogicHmm, this has broken Aegir, since we do a lot of backend calls and we usually use '--invoke' for that. I'll investigate whether switching to '--strict=0' will fix it for us.
Comment #9
ergonlogicIt looks like a pretty simple fix to Provision: #2038891: Switch from '--invoke' to '--strict=0' for backend calls
Comment #10
greg.1.anderson commentedIt seems to me that adding 'invoke' as Aegir has been doing shouldn't have been necessary, as Drush-5.x adds 'invoke' for all calls that go through backend invoke, I believe. Similarly, with the current code, we could add 'strict' => FALSE for all calls that go through backend invoke except for those that pass through drush_do_command_redispatch(), which is what drush_preflight_command_dispatch() uses when the user specifies a remote command via
drush @remote command.Maybe there is value to "syntax checking" invoked command options, though.
Comment #11
moshe weitzman commentedI want the syntax checking.
I can't reproduce the %dump-dir problem in #5.
Comment #12
moshe weitzman commentedMoving back to fixed. Please reopen if that dump-dir problem can be reproduced.
Comment #13
kostajh commentedI'm encountering the dump-dir problem.
With an alias that looks like:
The following command:
drush @example.stage pmlreturns:Comment #14
greg.1.anderson commentedI've got a fix; testing it against the test suite now.
Comment #15
greg.1.anderson commentedFixed in be9802e.
Comment #16
greg.1.anderson commentedIf entirely removing the alias-context options is too big of a change, there are two alternatives to consider:
1. Scan through the alias-context options, and include only those that are Drush global options.
2. Scan through the alias-context options, and add --strict=0 if any are found that are not Drush global options.
Without one of these changes, going back to including the alias-context options would not work, as you would run into the "option not recognized" problem nearly invariantly. We shouldn't require the user to know to insert 'strict' =>TRUE into an alias just because some other option is defined there.
Comment #17
greg.1.anderson commentedThe checked-in code is actually still broken for sql-sync; the addition of a user-defined option in a site alias will break sql-sync's use of sql-conf, preventing sql-sync from determining the site's database record.
Comment #18
greg.1.anderson commentedSince the checked-in code was broken, I committed bbf2463 to changes Drush so that it will only propagate option values from site aliases if they are global options (or inside command-specific records, as usual).
I didn't think that #16.2 was a good idea; that would essentially change the rule to "always do option checking, unless you have an option that does not check out". Re-open if you think that a user-defined top-level alias option such as 'foo' => 'bar' should be passed on the command line as --foo=bar in backend invoke calls, either in some or all instances.