Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / src / Style / DrushStyle.php
1 <?php
2
3 namespace Drush\Style;
4
5 use Drush\Drush;
6 use Drush\Exceptions\UserAbortException;
7 use Symfony\Component\Console\Style\SymfonyStyle;
8
9 class DrushStyle extends SymfonyStyle
10 {
11     public function confirm($question, $default = true)
12     {
13         // Automatically accept confirmations if the --yes argument was supplied.
14         if (Drush::affirmative()) {
15             $this->comment($question . ': yes.');
16             return true;
17         } // Automatically cancel confirmations if the --no argument was supplied.
18         elseif (Drush::negative()) {
19             $this->warning($question . ': no.');
20             return false;
21         }
22
23         $return = parent::confirm($question, $default);
24         return $return;
25     }
26
27     /**
28      * @param string $question
29      * @param array $choices
30      *   If an associative array is passed, the chosen *key* is returned.
31      * @param null $default
32      * @return mixed
33      */
34     public function choice($question, array $choices, $default = null)
35     {
36         $choices = array_merge(['cancel' => 'Cancel'], $choices) ;
37         $choices_values = array_values($choices);
38         $return = parent::choice($question, $choices_values, $default);
39         if ($return == 'Cancel') {
40             throw new UserAbortException();
41         } else {
42             return array_search($return, $choices);
43         }
44     }
45
46     public function warning($message)
47     {
48         $this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ! ', true);
49     }
50
51     public function note($message)
52     {
53         $this->block($message, 'NOTE', 'fg=black;bg=yellow', ' ! ');
54     }
55
56     public function caution($message)
57     {
58         $this->block($message, 'CAUTION', 'fg=black;bg=yellow', ' ! ', true);
59     }
60 }