Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We should make it easier for drush extensions to have their own rc files.
I'm very much open to ideas on the best way to approach this is but the attached patch lets commands specific their prefix in hook_drush_command, which turned out to be fairly simple.
So for deploy, I'd do:
$items['deploy'] = array(
'description' => '',
'arguments' => array(
),
'options' => array(
),
'examples' => array(
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'config' => 'deploy',
);
And then that would load any deploy.drushrc.php files that can be found in the usual locations.
Comment | File | Size | Author |
---|---|---|---|
#5 | command_config_support-5.patch | 1.91 KB | msonnabaum |
command_config_support.patch | 2.53 KB | msonnabaum |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedSo this file gets loaded instead of drushrc.php, and not in addition to? Thats a bit surprising, IMO. Anyway, I'm a bit skeptical on this. We have lived pretty successfully with command_specific. I want to keep drush s simple as possible and our myriad of searchpaths is complex enough. This adds another gotcha. Am open to opinions from others here.
Comment #2
msonnabaum CreditAttribution: msonnabaum commentedThis loads command configs in addition to, not instead (unless I messed something up there…).
My motivation here is that the deploy config can end up being pretty big and if I'm going to use drushrc and drush_get_option (which I want to), I'd be nice to separate it out into a new config file like we do with aliases.drushrc.php.
I'm not married to the idea of specifying it in a command, I just want a way to do it. A hook that a command file could implement would be fine as well.
Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commentedAn individual user can always add something like:
in their drushrc.php file, and copy all of the deploy settings into this auxiliary file, if desired. I see no reason to add complexity or try to increase performance by only loading these options when a deploy command is invoked.
We do special stuff for alias files because Aegir might have a thousand different aliases. I don't think that quite applies here.
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedI think this is Won't Fix. Perhaps deploy could ship with its own deploy.drushrc.php which tells folks to copy and paste into another drushrc or it could instruct folks to copy and include it.
Comment #5
msonnabaum CreditAttribution: msonnabaum commentedOk, so how about no autoloading of command configs, but we at least change _drush_config_file() so other command's can use it's logic.
That at least lets me do something like this:
I'm still duplicating a bit of code here, but it's considerably better than having to duplicate _drush_config_file().
And yes, there are a couple workarounds, but they are clunky. There's no reason drush shouldn't allow commands to do easily load command specific config files.
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedLooks good. If you could add some doxygen explaining $prefix that would be swell.
Comment #7
msonnabaum CreditAttribution: msonnabaum commentedAwesome. I documented @prefix as well as @context and committed this to master (cf1f64d ).
Comment #9
bjaspan CreditAttribution: bjaspan commentedAt Mark's suggestion I'm providing some new input here. I'm not sure if it argues for or against his proposed change. :-)
I wanted a command-specific (actually, a command-file-specific) drushrc file to store common options for a set of commands. I ended up doing this:
Then I use ahapi_get_option('name') instead of drush_get_option('name', 'default') for my common options, but continue using drush_get_option() for normal/global options like simulate, verbose, and debug. By loading ~/.drush/ahapi.drushrc.php via drush_load_config_file() at the top of ahapi_get_option(), I am able to store my commandfile-specific defaults there. I have a command, ah-api-login, that prompts for username/password and stashes it there.
After some amount of confusion and concern that by storing $options['username'] in ~/.drush/ahapi.drushrc.php I was polluting the global namespace, Mark, Moshe, and I came to the conclusion that ahapi.drushrc.php will never be loaded automatically by Drush; it is loaded only by my call to drush_load_config_file(), which only happens when one of my commands is running.
I guess the upshot is that if I could specify 'config' => 'ahapi' in my commands returned from ahapi_drush_command(), it would simplify my code slightly by removing the explicit call to drush_load_config_file(), and it would have simplified my life somewhat more by making it easier for me to create this setup instead of having to go figure out how drush_load_config_file() works.