Submitted by jeanseb on Thu, 12/19/2019 - 16:04

 Une fois drush installé pour l'utiliser il faut être dans un répertoire de l'arborescence de drupal pour qu'il détecte les modules installés (et donc leur commandes) .

L'exécution simple de la commande drush le mentionne en fin de message :

$ drush 
Drush Commandline Tool 9.2.1

Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more documentation.

 Available commands:                                                                                                
 _global:                                                                                                           
   help                                 Display usage details for a command.                                        
   list                                 List available commands.                                                    
   browse                               Display a link to a given path or open link in a browser.                   
   runserver (rs, serve)                Runs PHP's built-in http server for development.                            
   version                              Show Drush version.                                                         
   updatedb (updb)                      Apply any database updates required (as with running update.php).           
   generate (gen)                       Generate boilerplate code for modules/plugins/services etc.                 
   config:pull (cpull)                  Export and transfer config from one environment to another.                 
   pm:security (sec)                    Check Drupal Composer packages for pending security updates.                
   entity:updates (entup)               Apply pending entity schema updates.                                        
   updatedb:status (updbst)             List any pending database updates.                                          
   user:login (uli)                     Display a one time login link for user ID 1, or another user.               
   drupal:directory (dd)                Return the filesystem path for modules/themes and other key folders.        
 cache:                                                                                                             
   cache:get (cg)                       Fetch a cached object and display it.                                       
   cache:clear (cc)                     Clear a specific cache, or all Drupal caches.                               
   cache:set (cs)                       Cache an object expressed in JSON or var_export() format.                   
   cache:rebuild (cr, rebuild)          Rebuild a Drupal 8 site.                                                    
 core:                                                                                                              
   core:status (status, st)             An overview of the environment - Drush and Drupal.                          
   core:rsync (rsync)                   Rsync Drupal code or files to/from another server using ssh.                
   core:execute (exec, execute)         Execute a shell command. Usually used with a site alias.                    
   core:init (init)                     Enrich the bash startup file with bash aliases and a smart command prompt.  
   core:topic (topic)                   Read detailed documentation on a given topic.                               
   core:edit (conf, config)             Edit drushrc, site alias, and Drupal settings.php files.                    
 php:                                                                                                               
   php:eval (eval, ev)                  Evaluate arbitrary php code after bootstrapping Drupal (if available).      
   php:script (scr)                     Run php a script after a full Drupal bootstrap.                             
 site:                                                                                                              
   site:install (si, sin)               Install Drupal along with modules/themes/configuration/profile.             
   site:set (use)                       Set a site alias that will persist for the current session.                 
   site:alias (sa)                      Show site alias details, or a list of available site aliases.               
   site:alias-convert (sa-convert, sac) Convert legacy site alias files to the new yml format.                      
   site:ssh (ssh)                       Connect to a Drupal site's server via SSH.                                  
 sql:                                                                                                               
   sql:connect                          A string for connecting to the DB.                                          
   sql:create                           Create a database.                                                          
   sql:drop                             Drop all tables in a given database.                                        
   sql:cli (sqlc)                       Open a SQL command-line interface using Drupal's credentials.               
   sql:query (sqlq)                     Execute a query against a database.                                         
   sql:dump                             Exports the Drupal DB as SQL using mysqldump or equivalent.                 
   sql:sync                             Copy DB data from a source site to a target site. Transfers data via rsync. 

 ! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands.                  

Se placer dans le répertoire de drupal supprime le message mais nécessite encore de préciser l'url s'il n'y a pas de site par défaut.

Configurer drush permet entre autre d'éviter de préciser ce genre chose à chaque fois.

La première chose  à faire c'est de générer le squelette de la configuration avec la commande code:init de drush.
Vous n'êtes pas obligé de répondre oui à la demande de modification du fichier .bashrc.

$ drush core:init

 Modify /home/jeanseb/.bashrc to include Drush configuration files? (yes/no) [yes]:
 > 

 [notice] mkdir ["/home/jeanseb/.drush"]
 [notice] Writing to /home/jeanseb/.drush/drush.yml.
 [notice] Writing to /home/jeanseb/.drush/drush.bashrc.
 [ok] Copied Drush bash customizations to /home/jeanseb/.drush/drush.bashrc
 [notice] Writing to /home/jeanseb/.drush/drush.prompt.sh.
 [ok] Copied Drush prompt customizations to /home/jeanseb/.drush/drush.prompt.sh
 [notice] Writing to /home/jeanseb/.bashrc.
 [ok] Updated bash configuration file /home/jeanseb/.bashrc
 [ok] Start a new shell in order to experience the improvements (e.g. `bash`).
 11/11 [============================] 100%

Cette commande créé le répertoire .drush dans le répertoire home et y installe les fichiers de configuration.

Modifier les options dans drush.yml pour spécifier les options par défaut ne fonctionne pas

# This section is for setting global options.
options:
  # Specify the base_url that should be used when generating links.
  # Not recommended if you have more than one Drupal site on your system.
  uri: 'http://example.com/subdir'

  # Specify your Drupal core base directory (useful if you use symlinks).
  # Not recommended if you have more than one Drupal root on your system.
  root: '/home/USER/workspace/drupal-6'

  # Enable verbose mode.
  verbose: true

J'ai donc choisi pour contourner le problème de passer par la définition d'un alias appelé défault.
Pour cela j'ai créé dans le répertoire ~/drush un répertoire site.
Puis le fichier site.default.site.yml suivant :

common:
  root: '/home/www-data'
  uri: 'http://localhost'

Ensuite il faut faire un "drush use @default" en début de session,  pour éviter cela j'ai modifié le fichier drush.bashrc pour ajouter la commande (après les alias)  :

alias q='drush sql:query'

# Modification pour utiliser l'alias par defaut
drush use @default

# Overrides for standard shell commands. Uncomment to enable.  Alias

Notez que si vous avez refusé de modifier automatiquement le fichier .bashrc il vous faudra y ajouter la commande drush use.

Et voila une solution qui permet de se débarrasser du message " ! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands."