drush-ops / drush-launcher

A small wrapper around Drush for your global $PATH.
GNU General Public License v2.0
237 stars 50 forks source link

Drush launcher is not reading site aliases? #32

Closed jhuhta closed 7 years ago

jhuhta commented 7 years ago

One of my hosts has two Drupal 8.4.0-rc2 instances in different paths. Site aliases are properly configured. When my current working directory is outside these paths, all attempts to run drush end up with an error:

The Drush launcher could not find a Drupal site to operate on. Please do one of the following:

  • Navigate to any where within your Drupal project and try again.
  • Add --root=/path/to/drupal so Drush knows where your site is located.
  • Add a site alias so Drush knows where your site is located.

When run inside a Drupal dir, drush works mostly, but site aliases are still not read (they're configured outside the project). It seems to me that drush is not even trying to read drushrc.php or aliases from ~/.drush or /etc/drush without --config option. Should it? And even --config doesn't help outside the project.

If I replace drush launcher with Drush 8.1.3 in /usr/local/bin, everything works just fine. Is this an environment problem, user error or a bug or feature in the launcher? (Running Ubuntu 16 & PHP7, Drush 9.0.0-beta4)

krystianbuczak commented 7 years ago

Same symptom. Drush Launcher installed as global composer package, OS: Ubuntu.

Recognizes local Drush instance only if command ran inside Drupal's directory.

greg-1-anderson commented 7 years ago

The error message is in error -- site aliases have never been supported in the launcher, although this is an aspirational goal.

Try installing Drush 9 globally, and use that as a launcher for your site-local instances of Drush 8. Should work great, and supports aliases. Note that Drush 9 uses a .yml format for aliases, but it will auto-convert from the old style to the new style. This strategy will change by the release of Drush 9.0.0 stable -- you will need to explicitly run a command to convert your aliases to the new format. If Drush 9.0.0 works for you as a launcher, I'd recommend switching to use the .yml format.

If we do manage to add alias support to the launcher, we would use the .yml format.

weitzman commented 7 years ago

I removed that line from the error message. At this time, the launcher must have a local Drupal site before it can resolve any alias that is passed.

weitzman commented 7 years ago

When run inside a Drupal dir, drush works mostly, but site aliases are still not read (they're configured outside the project). It seems to me that drush is not even trying to read drushrc.php or aliases from ~/.drush or /etc/drush without --config option. Should it? And even --config doesn't help outside the project.

In beta5, Drush aliases (and commandfiles) are no longer auto-discovered in the global locations like ~/.drush or /etc/drush. If you want that behavior back, you need specify it in a drush.yml which can be located in a global location or local to the project. The code you need in the drush.yml goes like:

runtime:
    context:
        alias-path: 
         - /Users/moshe.weitzman/tmp/unish/drush-sandbox/etc/drush

This needs documenting somewhere.

greg-1-anderson commented 7 years ago

We were going to move this from runtime.context.alias-path to drush.alias-path. We should make that change before documenting.

greg-1-anderson commented 7 years ago

c.f. https://github.com/drush-ops/drush/pull/3010

hanoii commented 7 years ago

I don't quite understand this. Aren't global aliases like those present on ~/.drush/ read by drush and not the launcher.. and if so, why wouldn't they work from the site-local version on drupal on drush 8.x. Or that was removed too from that branch?

Are you saying that global aliases will never work?

greg-1-anderson commented 7 years ago

By default, Drush does not read alias files from global locations. To opt-in for this behavior, you need to set the valid alias locations in your drush.yml file.

This is now documented in the site aliases example.

hanoii commented 7 years ago

but isn't that a drush 9 thing? or would a drush.yml file work for drush 8? Where should I put that file?

What I meant is that if that my local version of drush is 8, that one does read from the global locations by default right?

# drush version
 Drush Version   :  8.1.14
# drush sa

Doesn't work

# ./vendor/bin/drush version
 Drush Version   :  8.1.14
# ./vendor/bin/drush sa

works.

Both run from the site site-local.

Using the latest launcher 0.4.2.

greg-1-anderson commented 7 years ago

Once the launcher has selected a particular Drupal site, it adds --local to turn off configuration from other locations.

hanoii commented 7 years ago

Thanks for the follow ups! Hmm, and why would it do that? I always thought as a launcher to select the proper version of drush, by why preventing global configs from being read, if that's what global configs are for. I guess I might be missing something, or maybe allow that to be optional for the launcher.. I guess I can edit it for the time being.

And.. would drush.yml work on drush8?

What would be the recommended way of using drush8 and global aliases with the launcher? What you suggested above, using drush9 globally as the launcher? That's a bit counterintuitive, why would I want a global drush 9 if the recommended way is having drush as a site-local setup.

jasonglisson commented 6 years ago

I'm finding this to be an issue when trying to run drush make with no Drupal site files at all. Is there a work around for this?