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.33k stars 1.08k forks source link

Add proxy objects for commands not available due to bootstrap #3036

Open greg-1-anderson opened 6 years ago

greg-1-anderson commented 6 years ago

It is very confusing to folks that commands such as pm:enable are invisible unless we have bootstrapped a Drupal site. While we cannot instantiate these commandfiles without a working Drupal 8 site due to their use of dependency injection, it would be possible to instead instantiate proxy commands for them, so that users could see which commands were available, and see a useful diagnostic message about bootstrapping if an unavailable command is executed.

weitzman commented 6 years ago

Mostly resolved by #3116

weitzman commented 6 years ago

Thats now merged. We now give a helpful error message in this situation but these commands are absent from help so I'll leave this open.

weitzman commented 5 years ago

Symfony 3.4 brought us lazy loaded commands - perhaps that makes this easier? Lazy loaded commands would speed up Drush a bit as well.

greg-1-anderson commented 5 years ago

I don't know that we need that; what we want is just a command that has the right metadata but does nothing. So, if you run Drush in a situation where a Drupal site cannot bootstrap, it could still take all of the annotation data from the Drupal/Commands and instantiate proxy commands so that "help" and "list" will work. If we also want this to work with module extensions, then we'd need a fast way to discover those extensions without bootstrapping. Drush 8 and earlier used to do this (still do this) for the 'list' and 'help' commands.

Lazy loaded commands allow proxy commands that also can do something if they are executed; we just want to print a message, so we can probably just make a regular Symfony Console command (or maybe a regular AnnotatedCommand).

In instances where we can bootstrap a Drupal site, we do bootstrap it in order to load its extension commands. We typically don't have heavyweight operations that need to be done before a command executes other than bootstrapping, so I'm not sure there are many places where lazy-loading would speed up Drush.