1

I've downloaded Coder (7.x-2.x) module in the following way:

drush -y dl coder-7.x-2.x --destination=~/.drush && drush cc drush

And I would like to call function (coder_review_reviews()) from drush (using eval) which is defined in ~/.drush/coder/coder_review/coder_review.common.inc and I need to include that file first, but I don't know how to determine my module path.

Normally when module is within Drupal root, you can use module_load_include() for that, but this function is not available when you're calling drush outside of your core. It seems I can't use dd either.

How can I achieve that without hardcoding the path to the module?

3

In Drush, the right way to do this is to use drush_invoke_process() to call a Drush function in coder that calls coder_review_reviews() for you, and returns the result as the function result of the Drush command implementation. I did not check to see if coder does this.

If the service you need is not exported, the alternative is to call drush_get_commandfiles(). The result you will get is a key / value pair, where the key 'coder' has the value of the full path to the coder.drush.inc file.

When commands do not export the functionality you need, it is better to submit a patch on their project providing the access you need. Directly including .inc files and calling internal functions is fragile, and at risk of breaking in new versions of the project.

0

So far I have found the following workaround by using ReflectionClass, for example:

drush ev 'require_once dirname((new ReflectionFunction("drush_coder_review"))->getFileName()) . "/coder_review.common.inc"; print_r(array_keys(coder_review_reviews()));'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.