It would be great if command files could extend the behavior of drush when bootstrapping.
Example: When using version control I have standardised locations for db dumps, and the drupal root directory usually isn't the root of the repo. I store a file (currently YAML, but probably moving to drupal .info style) that contains info for the project. When running drush from outside the drupal root I have a command file that will look for this file, and if found preset many drush options (such as drupal root) from the info found in it.
To make this work, I am currently using the attached patch. This provide 4 hooks for each bootstrap phase: HOOK_BOOSTRAP_PHASE_pre_validate, HOOK_BOOTSTRAP_PHASE_post_validate, HOOK_pre_BOOTSTRAP_PHASE, HOOK_post_BOOTSTRAP_PHASE. Sadly some of the phases that start with undercores have rather unusual function signatures. The other downside to this method is that several of the first hooks cannot be used, since the command files are not parsed yet. I.e. the first three hooks while technically valid will never be called: HOOK__drush_bootstrap_drush_pre_validate(), HOOK__drush_bootstrap_drush_post_validate(), HOOK_pre__drush_bootstrap_drush(). The first valid bootstrap hook is HOOK_post__drush_bootstrap_drush().
Thoughts?
| Comment | File | Size | Author |
|---|---|---|---|
| drush_bootstrap_hooks.patch | 1.75 KB | mikey_p |
Comments
Comment #1
greg.1.anderson commentedWhile the patch is simple, I for one have a vaguely uneasy feeling about this. Poorly-behaved bootstrap hooks could make diagnosing and debugging bootstrap problems difficult.
Are there perhaps other solutions to your problem? Couldn't you just put some php code in one of your drushrc files to locate your custom drushrc file? _drush_bootstrap_drush will load config files from drush, system and user before loading custom, so if you set $options['c'] in /etc/drushrc.php or $HOME/.drushrc.php, the file you point at will be loaded, and you can initialize the drush options you need as you like. You could also just include or require your custom file directly from your drushrc file.
I haven't tried this, but I think this would be a better solution than introducing bootstrap hooks.
Comment #2
mikey_p commentedOkay thanks, I'll give this a try.
I've tried explaining what I'd like to do before, but without actually doing it and posting the patch it was hard to explain/understand, but this looks like I'll be able to hook into the process at roughly the exact same point.
This might be an question for another issue, but has there been any though with allowing config files to use the .info file syntax?
Comment #3
greg.1.anderson commentedWhy would you want to do that?
Comment #4
moshe weitzman commentedgreg's suggestion seems to resolve this.