Permalink
Browse files

Implement @hook interact and @hook init.

  • Loading branch information...
1 parent 21d6309 commit 36aed497d374738decf06715c2a29256b7c691d3 @greg-1-anderson greg-1-anderson committed Dec 29, 2016
Showing with 25 additions and 2 deletions.
  1. +11 −1 includes/annotationcommand_adapter.inc
  2. +14 −1 lib/Drush/Commands/core/WatchdogCommands.php
@@ -212,6 +212,7 @@ function annotationcommand_adapter_process_command() {
$args[$key] = $value;
}
+ // TODO: Need to determine if $input is interactive, and ensure that $input->isInteractive() returns the correct result.
$input = new DrushInputAdapter($args, annotationcommand_adapter_get_options($command), $command['command']);
$output = new ConsoleOutput();
$annotationData = $command['annotations'];
@@ -223,7 +224,16 @@ function annotationcommand_adapter_process_command() {
$commandData->setIncludeOptionsInArgs($command['add-options-to-arguments']);
$names = annotationcommand_adapter_command_names($command);
- // n.b.: backend result is set by a post-alter hook.
+ // Run any `@hook init` for this command. c.f. AnnotatedCommand::initialize()
+ $commandprocessor->initializeHook($input, $names, $annotationData);
+
+ // Run any `@hook interact` for this command. c.f. AnnotatedCommand::interact()
+ if ($input->isInteractive()) {
+ $commandprocessor->interact($input, $output, $names, $annotationData);
+ }
+
+ // Run any validate, command, process, alter or handle results hooks. c.f. AnnotatedCommand::execute()
+ // n.b.: backend result is set by a global post-alter hook.
$result = $commandprocessor->process(
$output,
$names,
@@ -64,6 +64,10 @@ function show($substring = '', $options = ['format' => 'table', 'count' => 10, '
public function interactShow($input, $output) {
drush_include_engine('drupal', 'environment');
+ if ($this->hasSeverityOrTypeOption($input)) {
+ return;
+ }
+
$choices['-- types --'] = dt('== message types ==');
$types = drush_watchdog_message_types();
foreach ($types as $key => $type) {
@@ -76,6 +80,8 @@ public function interactShow($input, $output) {
}
$option = drush_choice($choices, dt('Select a message type or severity level.'));
if ($option === FALSE) {
+ // TODO: We need to throw an exception to abort from an interact hook.
+ // Need to define an abort type and catch it.
return drush_user_abort();
}
if (isset($types[$option])) {
@@ -86,6 +92,13 @@ public function interactShow($input, $output) {
}
}
+ protected function hasSeverityOrTypeOption($input) {
+ if ($input->getOption('type', false) || $input->getOption('severity', false)) {
+ return true;
+ }
+ return false;
+ }
+
/**
* Delete watchdog log records.
*
@@ -282,4 +295,4 @@ function formatResult($result, $extended = FALSE) {
return $result;
}
-}
+}

0 comments on commit 36aed49

Please sign in to comment.