This patch adds the ability to enable or disable modules and themes by use of a 'wildcard' when specifying the module/theme name.

Using context module as an example, currently you do this:

drush en context context_ui context_contrib

to get all the context* modules enabled, this patch saves you a few keystrokes:

drush en context*

Useful?

I arrived at the party late, I only installed drush yesterday so I may not be aware of all the shortcuts and best practices.

Thanks for a great module, drush rocks!

Comments

matason’s picture

StatusFileSize
new1.1 KB

And the patch...

psynaptic’s picture

Applied the patch, tested and it works.

matason’s picture

StatusFileSize
new1.09 KB

Attached an improved patch, thanks to code review from @psynaptic and @snufkin :)

mcjim’s picture

This makes perfect sense. Only been using it sine this morning and it's already become part of my workflow.
Works as expected.

greg.1.anderson’s picture

Status: Needs review » Needs work

Useful, but the fact that the * has to go on the end could cause some head-scratching. Would it be possible to make it more general-purpose? Needs some documentation. Good work overall.

matason’s picture

Thanks for the reviews, @greg.1.anderson can you elaborate on how you think * at the end is confusing and ideas on making it more general purpose?

greg.1.anderson’s picture

I think I could probably go with * on the end only if it was a documented limitation, but Moshe would have to agree. The reason it might be confusing is that the user, after using drush pm-enable context* could naturally expect to also be able to use drush pm-enable *foo* to enable a bunch of modules that happened to have a common string somewhere in the middle. This could be quite a time-waster if there was no documentation on the limitation.

Even if the limitation is removed, docs are needed.

Thanks for your work.

matason’s picture

Status: Needs work » Needs review
StatusFileSize
new2.94 KB

Thanks for the comments, I see what you mean - I can't recall ever wishing I was able to enable/disable modules using some sort of *foo* criteria (maybe some people do and as you rightly point out it could be a time waster for someone) however within 2 mins of installing drush and using it to dl views and context I was looking for an option such as 'drush en views* context*'

I guess it's partly because when you download views you get not only views but views_ui and views_export that I wanted some easy way to switch them all on without having to name the sub modules explicitly.

I agree on the point about documentation so in the attached patch I've added some lines and examples to hook_drush_help().

Do you think that is sufficient or is there more I could do on documentation?

moshe weitzman’s picture

Code looks fine.

Sorry to scope creep, but we need consistency across commands. Lets identify which other commands would need same functionality

matason’s picture

Status: Needs review » Needs work

Good thinking Moshe, I'll have a look through the commands and identify which would benefit from this.

greg.1.anderson’s picture

This would be applicable to pm-disable, pm-info, pm-update, pm-updatecode and pm-uninstall.

matason’s picture

Thanks @greg.1.anderson - I've been rummaging through drush code looking at these commands and so far it seems to me that they fall into two distinct types, commands that operate on the project release information (i.e. the 'main' module like views or context etc) and commands that can take (sometimes optional) a space separated list of module/theme names to operate on. I think it's these latter commands only which might benefit from this feature.

I've been through the following commands, I tried to follow them through to the functions they are calling in Drupal and to identify how they are working and whether this feature is appropriate or even needed...

pm-disable (dis) - so this works with the patch on comment 3, although drush already adds all the dependent modules to the list of modules it will disable so assuming you have views, views_ui and views_export installed issuing:

drush pm-disable views

produces

The following projects will be disabled: views, views_export, views_ui

pm-download (dl) - I don't think anything is needed here, all sub modules are downloaded when a main module is downloaded
pm-enable (en) - works with the patch on comment 3
pm-info - I think this command would benefit from the feature, I'll work on a revised patch
pm-list (sm) - nothing needed here, the command lists all sub modules anyway
pm-refresh (rf) - doesn't take any arguments, nothing needed here
pm-releases - I haven't thoroughly followed this command through but from testing it appears to work on project release info so passing in views_ui understandably returns "No information available."
pm-uninstall - not sure about this one, I need to dig deeper but it dependent modules are uninstalled by default by Drupal? With that in mind I don't think adding this feature makes sense for this command?
pm-update (up) - not needed, like pm-releases pm-update works on the main project info only
pm-updatecode (upc) - same as pm-update

So in summary I think pm-info appears to be the only additional candidate for this feature, I'll dig deeper into pm-uninstall and see what I can find.

As ever thoughts, comments and corrections appreciated ;o)

matason’s picture

Status: Needs work » Needs review
StatusFileSize
new2.36 KB

I've pulled out the code that expands the project names into it's own function so that it can be called from wherever and I've added the feature to the pm-info command as well.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. I wonder if jonhattan or Owen have any comments? I'll commit this soon if we get no feedback.

moshe weitzman’s picture

Status: Reviewed & tested by the community » Needs work

We need to document the * feature for the commands that support it. It can be a sentence in the 'arguments' array.

matason’s picture

Status: Needs work » Needs review
StatusFileSize
new4.61 KB

Hi Moshe,

In the attached patch I've added an explanation and example in README.txt and also added to the 'arguments' array as suggested.

moshe weitzman’s picture

Status: Needs review » Needs work

Thanks.

Lets omit mention of this feature in the README and change the text in pm-enable and pm-disable so that it mentions modules and submodules instead of projects and subprojects. The pm-info text and the _drush_pm_expand_projects () function name can stay as is.

matason’s picture

Status: Needs work » Needs review
StatusFileSize
new3.84 KB

Hi Moshe,

Okay, the attached patch has the changes you mentioned.

moshe weitzman’s picture

Status: Needs review » Fixed

committed. thanks for your persistence.

matason’s picture

That's great, thanks Moshe.

jonhattan’s picture

The command description says:

You can use the * wildcard at the end of module and theme names to enable the modules and all its submodules.

I think it is not all the submodules but all modules with the specified name as a prefix. That is: views, views_ui, views_bulk_operations. The later is not a submodule of the project views.

On the other hand, a project can have submodules with a name that is not a prefix. For example cck: content, fieldgroup, nodereference,...

greg.1.anderson’s picture

Status: Fixed » Active

Yes, I agree that the message should be changed. Marking active.

moshe weitzman’s picture

Status: Active » Fixed

Slightly improved message. Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.