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