DrupliconCommands.php

Namespace

Drush\CommandFiles\core

Classes

Namesort descending Description
DrupliconCommands

File

lib/Drush/CommandFiles/core/DrupliconCommands.php
View source
  1. <?php
  2. namespace Drush\CommandFiles\core;
  3. use Consolidation\AnnotatedCommand\CommandData;
  4. use Drush\CommandFiles\DrushCommands;
  5. class DrupliconCommands extends DrushCommands {
  6. protected $printed = false;
  7. /**
  8. * Print druplicon as post-command output.
  9. *
  10. * @hook post-command *
  11. * @option druplicon Shows the druplicon as glorious ASCII art.
  12. * @todo hidden is not yet part of annotated-command project. It is recognized by Drush's annotation_adapter.inc
  13. * @hidden-option druplicon
  14. */
  15. public function druplicon($result, CommandData $commandData) {
  16. // If one command does a drush_invoke to another command,
  17. // then this hook will be called multiple times. Only print
  18. // once. (n.b. If drush_invoke_process passes along the
  19. // --druplicon option, then we will still get mulitple output)
  20. if ($this->printed) {
  21. return;
  22. }
  23. $this->printed = true;
  24. $annotationData = $commandData->annotationData();
  25. $commandName = $annotationData['command'];
  26. // For some reason, Drush help uses drush_invoke_process to call helpsingle
  27. if ($commandName == 'helpsingle') {
  28. return;
  29. }
  30. if ($commandData->input()->getOption('druplicon')) {
  31. $this->logger()->debug(dt('Displaying Druplicon for "!command" command.', array('!command' => $commandName)));
  32. $misc_dir = DRUSH_BASE_PATH . '/misc';
  33. if (drush_get_context('DRUSH_NOCOLOR')) {
  34. $content = file_get_contents($misc_dir . '/druplicon-no_color.txt');
  35. }
  36. else {
  37. $content = file_get_contents($misc_dir . '/druplicon-color.txt');
  38. }
  39. // @todo: `$commandData->output->writeln($content)` after $output hooked up to backend invoke
  40. drush_print($content);
  41. }
  42. }
  43. }