1

I've added new option into drush command as suggested here:

function hook_drush_help_alter(&$command) {
  if ($command['command'] == 'features-revert-all') {
    $command['options']['cleanup'] = 'Remove non-existing components.';
  }
}

where features-revert-all is overridden by another created custom command as demonstrated here (so basically another custom-features-revert-all command is called).

However when my custom command invoking another commands via drush_invoke - they fail, because they cannot find that option. I really don't care about the option whether they can recognise it or not, but they shouldn't fail.

So basically when I run:

drush fra --cleanup --yes

I've these errors:

Unknown option: --cleanup. See drush help features-cleanup-feature for available options. To suppress this error, add the option --strict=0.

Unknown option: --cleanup. See drush help rules-revert-all for available options. To suppress this error, add the option --strict=0.

Here is how my function look (simplified for clarity):

function drush_FOO_custom_features_revert_all() {
  module_load_include('inc', 'features', 'features.export');
  $force = drush_get_option('force');
  $cleanup = drush_get_option('cleanup'); // At this point, the option is working.

  $features_to_revert = features_get_features(NULL, TRUE);
  if ($cleanup) {
    drush_invoke("features-cleanup-feature", $features_to_revert);
  }
  else {
    drush_invoke("features-revert", $features_to_revert);
  }
  drush_invoke('rules-revert-all');
}

So basically the option works fine within the main function, but sub-commands are complaining that this option that it's unknown to them.

Question is, what's the correct approach of fixing it (so they won't fail)?

Do I need to add option to every other command which uses drush_invoke into drush_help_alter? Maybe there is some way of passing original drush options along. Or maybe I am forced to use --strict=0? Or there is some better way of fixing this issue?

  • 1
    I found something about that, when I was looking to implement a Drush command, but I cannot find it right now. – kiamlaluno Apr 28 '16 at 19:01
2

The preferred solution is to use drush_invoke_process() for subtasks. This will execute the command in its own process, completely isolate from the parent.

If you do need or wish to use drush_invoke() (doing so is a little faster, since you don't need to bootstrap again), then you should use drush_set_option('strict', 0); to disable options checking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.