1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Karma\Console; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Karma\Display\CliTable; |
11
|
|
|
use Karma\Command; |
12
|
|
|
|
13
|
|
|
class Diff extends Command |
14
|
|
|
{ |
15
|
36 |
|
protected function configure(): void |
16
|
|
|
{ |
17
|
36 |
|
parent::configure(); |
18
|
|
|
|
19
|
|
|
$this |
20
|
36 |
|
->setName('diff') |
21
|
36 |
|
->setDescription('Display differences between environment variable set') |
22
|
|
|
|
23
|
36 |
|
->addArgument('env1', InputArgument::REQUIRED, 'First environment to compare') |
24
|
36 |
|
->addArgument('env2', InputArgument::REQUIRED, 'Second environment to compare') |
25
|
|
|
; |
26
|
36 |
|
} |
27
|
|
|
|
28
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
29
|
|
|
{ |
30
|
1 |
|
parent::execute($input, $output); |
31
|
|
|
|
32
|
1 |
|
$environment1 = $input->getArgument('env1'); |
33
|
1 |
|
$environment2 = $input->getArgument('env2'); |
34
|
|
|
|
35
|
1 |
|
$output->writeln(sprintf( |
36
|
1 |
|
"<info>Diff between <comment>%s</comment> and <comment>%s</comment></info>\n", |
37
|
|
|
$environment1, |
38
|
|
|
$environment2 |
39
|
|
|
)); |
40
|
|
|
|
41
|
1 |
|
$diff = $this->app['configuration']->compareEnvironments($environment1, $environment2); |
42
|
|
|
|
43
|
1 |
|
$output->writeln(''); |
44
|
|
|
|
45
|
1 |
|
$table = new CliTable($diff); |
46
|
|
|
|
47
|
1 |
|
$table->enableFormattingTags() |
48
|
1 |
|
->setHeaders(array($environment1, $environment2)) |
49
|
1 |
|
->displayKeys() |
50
|
1 |
|
->setValueRenderingFunction(function($value){ |
51
|
1 |
|
return $this->formatValue($value); |
52
|
1 |
|
}); |
53
|
|
|
|
54
|
1 |
|
$output->writeln($table->render()); |
55
|
|
|
|
56
|
1 |
|
return 0; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|