1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nimble\ElasticBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
7
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
abstract class AbstractBaseCommand extends ContainerAwareCommand |
11
|
|
|
{ |
12
|
|
|
const TASKS_PAD_LENGTH = 88; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Configures common formatting. |
16
|
|
|
*/ |
17
|
|
|
protected function configureFormatter(OutputInterface $output) |
18
|
|
|
{ |
19
|
|
|
$output->getFormatter()->setStyle('info', new OutputFormatterStyle( |
20
|
|
|
'blue', null |
21
|
|
|
)); |
22
|
|
|
|
23
|
|
|
$output->getFormatter()->setStyle('error', new OutputFormatterStyle( |
24
|
|
|
'red', null |
25
|
|
|
)); |
26
|
|
|
|
27
|
|
|
$output->getFormatter()->setStyle('success', new OutputFormatterStyle( |
28
|
|
|
'green', null |
29
|
|
|
)); |
30
|
|
|
|
31
|
|
|
$output->getFormatter()->setStyle('warning', new OutputFormatterStyle( |
32
|
|
|
'yellow', null |
33
|
|
|
)); |
34
|
|
|
|
35
|
|
|
$output->getFormatter()->setStyle('graphic', new OutputFormatterStyle( |
36
|
|
|
'cyan', null |
37
|
|
|
)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param OutputInterface $output |
42
|
|
|
* @return ProgressBar |
43
|
|
|
*/ |
44
|
|
|
protected function createProgressBar(OutputInterface $output) |
45
|
|
|
{ |
46
|
|
|
$progress = new ProgressBar($output); |
47
|
|
|
|
48
|
|
|
$progress->setBarWidth(50); |
49
|
|
|
$progress->setFormat('%current%/%max% (%percent:2s%%) [%bar%] <info>%elapsed:6s%</info> (EST %estimated:6s%) %memory:6s%'); |
50
|
|
|
$progress->setBarCharacter('<success>=</success>'); |
51
|
|
|
$progress->setProgressCharacter('<success>></success>'); |
52
|
|
|
$progress->setEmptyBarCharacter('<error>=</error>'); |
53
|
|
|
|
54
|
|
|
return $progress; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param OutputInterface $output |
59
|
|
|
* @param string $name |
60
|
|
|
*/ |
61
|
|
|
protected function writeTaskStart(OutputInterface $output, $name) |
62
|
|
|
{ |
63
|
|
|
$output->write(str_pad(sprintf('<graphic>•</graphic> %s ', $name), self::TASKS_PAD_LENGTH, '.', STR_PAD_RIGHT)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param OutputInterface $output |
68
|
|
|
*/ |
69
|
|
|
protected function writeTaskSuccess(OutputInterface $output) |
70
|
|
|
{ |
71
|
|
|
$output->writeln(' <success>✓</success>'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param OutputInterface $output |
76
|
|
|
*/ |
77
|
|
|
protected function writeTaskFailure(OutputInterface $output) |
78
|
|
|
{ |
79
|
|
|
$output->writeln(' <error>✗</error>'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param OutputInterface $output |
84
|
|
|
* @param string $message |
85
|
|
|
*/ |
86
|
|
|
protected function writeSuccessMessage(OutputInterface $output, $message = '') |
87
|
|
|
{ |
88
|
|
|
$output->writeln("\n" . '<success>✓</success> ' . $message); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param OutputInterface $output |
93
|
|
|
* @param string $message |
94
|
|
|
*/ |
95
|
|
|
protected function writeErrorMessage(OutputInterface $output, $message = '') |
96
|
|
|
{ |
97
|
|
|
$output->writeln("\n" . '<error>✗</error> ' . $message); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|