424d4ba76c19ed87ed23296053f7d4e3ae9c829e
[yaffs-website] / vendor / drush / drush / src / Commands / core / DrupliconCommands.php
1 <?php
2 namespace Drush\Commands\core;
3
4 use Consolidation\AnnotatedCommand\AnnotationData;
5 use Consolidation\AnnotatedCommand\CommandData;
6 use Drush\Commands\DrushCommands;
7 use Symfony\Component\Console\Command\Command;
8 use Symfony\Component\Console\Input\InputOption;
9
10 class DrupliconCommands extends DrushCommands
11 {
12     protected $printed = false;
13
14     /**
15      * @hook option *
16      * @option druplicon Shows the druplicon as glorious ASCII art.
17      */
18     public function optionset($options = ['druplicon' => false])
19     {
20     }
21
22     /**
23      * Print druplicon as post-command output.
24      *
25      * @hook post-command *
26      */
27     public function druplicon($result, CommandData $commandData)
28     {
29         // If one command does a drush_invoke to another command,
30         // then this hook will be called multiple times. Only print
31         // once.  (n.b. If drush_invoke_process passes along the
32         // --druplicon option, then we still get multiple output)
33         if ($this->printed) {
34             return;
35         }
36         $this->printed = true;
37         $annotationData = $commandData->annotationData();
38         $commandName = $annotationData['command'];
39         if ($commandData->input()->hasOption('druplicon') && $commandData->input()->getOption('druplicon')) {
40             $this->logger()->debug(dt('Displaying Druplicon for "!command" command.', ['!command' => $commandName]));
41             $misc_dir = DRUSH_BASE_PATH . '/misc';
42             if ($commandData->input()->getOption('no-ansi')) {
43                 $content = file_get_contents($misc_dir . '/druplicon-no_color.txt');
44             } else {
45                 $content = file_get_contents($misc_dir . '/druplicon-color.txt');
46             }
47             $commandData->output()->writeln($content);
48         }
49     }
50 }