I use php-eval (ev) regularly in my daily workflow, but it's almost always something like:

drush ev "drush_print_r(module_list())"

Typing out drush_print_r is tedios, so I added the php-return (ret) command:

drush ret "module_list()"

Works exactly the same way as ev, but requires code that returns a value.

Also supports the usual "format" options:

drush ret "module_list()" --format=json
CommentFileSizeAuthor
#1 php-return.patch1.42 KBmsonnabaum

Comments

msonnabaum’s picture

StatusFileSize
new1.42 KB

Forgot patch.

greg.1.anderson’s picture

I like it, but how about calling it php-print, aliased to pp (or maybe just p)?

msonnabaum’s picture

Yeah, I had first thought of print, that might be best. I have no attachment to the name at all.

moshe weitzman’s picture

Status: Active » Needs work

Nice feature.

Option is not documented.

What about extending existing eval command? We would only do the print/export/json when a --format is specified.

greg.1.anderson’s picture

Version: » 8.x-6.x-dev
Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.