drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

How to "detect" a site’s URI based on the current working directory? #3345

Open torotil opened 6 years ago

torotil commented 6 years ago

Hi I’d really like to make drush detect the correct uri based on the current working directory (without extra arguments to drush).

Currently I’m using #2580 with a site-specific drushrc.php to achieve this. The maintainers of drush seem not in favor of that solution though (see #1965 and #2055).

As I’m not willing to maintain a drush fork ;) I’m looking for another way to achieve this. Any suggestions?

weitzman commented 6 years ago

Are you asking about drush9 or drush8? please describe your setup a bit more.

torotil commented 6 years ago

This is about a Drupal7 multi-site setup. I’m happy to use whatever drush version works. Up to now I have used a patched version of drush8.

A basic test-setup would look like this:

What I want to achieve is that the correct -l argument is automatically set based on the current shell working directory. In an imaginary shell session this would look like:

$ cd /drupal-root
$ drush status | grep URI
Site URI: https://default.example.com
$ cd sites/a
$ drush status | grep URI
Site URI: https://a.example.com

With the patch in #2580 I can do that when each sites folder contains a drushrc.php with a line like $options['l'] = 'https://default.example.com';

weitzman commented 6 years ago

Thanks for elaborating ... I dont have a suggestion offhand.

weitzman commented 6 years ago

My understanding is that your drushrc.php approach should work with drush8. But we have certainly received reports of it not working - #2285. If that issue matches this one, please close this as a dupe.

No solution exists yet for drush9

torotil commented 6 years ago

@weitzman As far as I understood #2285 is something completely different. I only have one global drush installation but I want it to detect and use the correct site/*/drushrc.php early enough to be able to configure the site url there as described in the imaginary shell session above. [… or any other means to achieve the same goal.]

torotil commented 6 years ago

Ok never mind. It seems that it does indeed work with 8.1.9.

torotil commented 5 years ago

Ok it seems I was wrong after all. It seems the installation I tested already had the patch from #2580. At least it does not work out-of-the-box with drush 8.1.18.

I found a fix that can be included in $HOME/.drush/drushrc.php though:

$site_path = drush_site_path();
if (file_exists("$site_path/drushrc.php")) {
  include "$site_path/drushrc.php";
}

With these lines the above shell session works. Without it I get a simple http://a as URI.

weitzman commented 5 years ago

Drush9 equivalent #3968