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