Description:

When implementing your own Drush commands, if you get the hook name wrong, drush_invoke stays silent, even if no hooks at all for the command are found.

So for example, if you implement a command called "deploy site" in a command file deploy.drush.inc and use the wrong function name for the command hook, even with --debug and --verbose on, the only information that is output is:

  Found command: deploy site [0.556 sec]                [bootstrap]

This lack of information is quite confusing for a developer starting out with Drush, given that hook naming system is so flexible (which is great btw).

Suggested Enhancement:

If a command is found but no hooks are found for that command, a log message of level 'error' is output with information such as:

  Could not find a hook for command "deploy site".
  You may implement any of the following functions:
    - drush_deploy_deploy_site()
    - drush_deploy_deploy_site_validate()
    - drush_deploy_pre_deploy_site()
    - drush_deploy_post_deploy_site()
    - etc etc etc

This would certainly help new drush developers - I ended up debugging around in drush_invoke in order to find out what drush was actually looking for.

If you think this is a worthwhile addition, I'm happy to submit a patch. I'm checking here first to find out if it's worthwhile.

Comments

moshe weitzman’s picture

I think it is worthwhile. Might be better as a warning and not an error.

moshe weitzman’s picture

Assigned: Unassigned » greg.1.anderson

greg is now a dispatch expert. assigning to him.

greg.1.anderson’s picture

Status: Active » Needs review

Good call.

The code looks something like this:

  // If no hook functions were found, print a warning.
  if (empty($functions)) {
    drush_log(dt("No hook functions were found for !command.", array('!command' => $command)), 'warning');
  }
  // In debug mode, we will also print all available function names.
  drush_log(dt("Available drush_invoke() hooks for !command: !available", array('!command' => $command, '!available' => "\n" . implode("\n", $all_available_hooks))), empty($functions) ? 'warning' : 'debug');

n.b. The available hook function list switches from a debug message to a warning when no hook functions are found.

However, to avoid problems with source merging, I'm going to put the patch in with #625920: Commands with explicit callback functions skip drush_invoke() API instead.

moshe weitzman’s picture

Status: Needs review » Fixed

got fixed with #625920: Commands with explicit callback functions skip drush_invoke() API. You now see 2 warnings. The second one is very long and very helpful (i misnamed the example callback to generate this output).

~/htd/dr6tmp$ drush example-foo
No hook functions were found for example-foo.                                                                                                   [warning]
Available drush_invoke() hooks for example-foo:                                                                                                 [warning]
drush_core_example_foo_validate
drush_devel_generate_example_foo_validate
drush_drush_make_example_foo_validate
drush_example_foo_validate
drush_installsite_example_foo_validate
drush_mw_example_foo_validate
drush_phpshell_example_foo_validate
drush_pm_example_foo_validate
drush_search_example_foo_validate
drush_simpletest_example_foo_validate
drush_sitealias_example_foo_validate
drush_sql_example_foo_validate
drush_upgrade_example_foo_validate
drush_variable_example_foo_validate
drush_watchdog_example_foo_validate
drush_core_pre_example_foo
drush_devel_generate_pre_example_foo
drush_drush_make_pre_example_foo
drush_example_pre_example_foo
drush_installsite_pre_example_foo
drush_mw_pre_example_foo
drush_phpshell_pre_example_foo
drush_pm_pre_example_foo
drush_search_pre_example_foo
drush_simpletest_pre_example_foo
drush_sitealias_pre_example_foo
drush_sql_pre_example_foo
drush_upgrade_pre_example_foo
drush_variable_pre_example_foo
drush_watchdog_pre_example_foo
drush_core_example_foo
drush_devel_generate_example_foo
drush_drush_make_example_foo
drush_example_foo
drush_installsite_example_foo
drush_mw_example_foo
drush_phpshell_example_foo
drush_pm_example_foo
drush_search_example_foo
drush_simpletest_example_foo
drush_sitealias_example_foo
drush_sql_example_foo
drush_upgrade_example_foo
drush_variable_example_foo
drush_watchdog_example_foo
drush_core_post_example_foo
drush_devel_generate_post_example_foo
drush_drush_make_post_example_foo
drush_example_post_example_foo
drush_installsite_post_example_foo
drush_mw_post_example_foo
drush_phpshell_post_example_foo
drush_pm_post_example_foo
drush_search_post_example_foo
drush_simpletest_post_example_foo
drush_sitealias_post_example_foo
drush_sql_post_example_foo
drush_upgrade_post_example_foo
drush_variable_post_example_foo
drush_watchdog_post_example_foo

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.