|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Magallanes package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Andrés Montañez <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Mage\Command\BuiltIn\Config; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
16
|
|
|
use Mage\Command\AbstractCommand; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Command for listing all the Environments |
|
20
|
|
|
* |
|
21
|
|
|
* @author Andrés Montañez <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class EnvironmentsCommand extends AbstractCommand |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Configure the Command |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
|
|
->setName('config:environments') |
|
32
|
|
|
->setDescription('List all Magallanes configured Environments') |
|
33
|
|
|
; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the Command |
|
38
|
|
|
* |
|
39
|
|
|
* @param InputInterface $input |
|
40
|
|
|
* @param OutputInterface $output |
|
41
|
|
|
* @return int|mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->requireConfig(); |
|
46
|
|
|
|
|
47
|
|
|
$output->writeln('Starting <fg=blue>Magallanes</>'); |
|
48
|
|
|
$output->writeln(''); |
|
49
|
|
|
|
|
50
|
|
|
$table = new Table($output); |
|
51
|
|
|
$table->setHeaders(['Environment', 'User', 'Branch', 'Hosts']); |
|
52
|
|
|
|
|
53
|
|
|
$configuration = $this->runtime->getConfigOption('environments'); |
|
54
|
|
|
foreach ($configuration as $environment => $config) { |
|
55
|
|
|
$row = [$environment]; |
|
56
|
|
|
|
|
57
|
|
|
$row[] = (isset($config['user']) ? $config['user'] : '-'); |
|
58
|
|
|
$row[] = (isset($config['branch']) ? $config['branch'] : '-'); |
|
59
|
|
|
$row[] = (isset($config['hosts']) ? implode(PHP_EOL, $config['hosts']) : '-'); |
|
60
|
|
|
|
|
61
|
|
|
$table->addRow($row); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$table->render(); |
|
65
|
|
|
|
|
66
|
|
|
$output->writeln(''); |
|
67
|
|
|
$output->writeln('Finished <fg=blue>Magallanes</>'); |
|
68
|
|
|
|
|
69
|
|
|
return 0; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|