I am expecting that drush_get_commands() will return all drush commands including from modules such as 'feature', but it is not when called within my Drush custom command. How to retrieve all drush commands available for the current drupal instance including ones provided from custom modules? Thank You
It is important to remember that
drush_get_commands() is sensitive to the bootstrap level that your command has reached. You must have bootstrapped a Drupal site before Drush commands associated with modules in that site are available via
drush_get_commands(). There are several requirements for this to be true.
You must have selected a Drupal site when you ran your custom Drush command, either by using a site alias (e.g. drush @mysite), or via commandline options (e.g. drush --root=/path/to/drupal --uri=mysite.org), or by setting your current working directory to the same directory that contains the settings.php file for your site.
Your custom command must declare a bootstrap level that is high enough to bootstrap a Drupal site. For example,
DRUSH_BOOTSTRAP_DRUSHis not sufficient, but
DRUSH_BOOTSTRAP_FULLis. If your command has not bootstrapped to a high enough level, you may call
drush_bootstrap_max()to finish bootstrapping the selected site.
Drush commands will only be loaded for enabled modules.
If you do all of these things, then you should see all commands for all modules when you call
drush_get_commands(). If you don't, try
drush cc drush to clear the commandfile cache.
(As a side note, do not use
drush_get_commands() as a way to call other Drush commands from your custom commandfile. Instead, use