|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Laravel-Env-Sync |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julien Tant - Craftyx <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Jtant\LaravelEnvSync\Console; |
|
9
|
|
|
|
|
10
|
|
|
use Illuminate\Console\Command; |
|
11
|
|
|
use Jtant\LaravelEnvSync\Reader\ReaderInterface; |
|
12
|
|
|
use Jtant\LaravelEnvSync\SyncService; |
|
13
|
|
|
|
|
14
|
|
|
class DiffCommand extends BaseCommand |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The name and signature of the console command. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $signature = 'env:diff {--src=} {--dest=}'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The console command description. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $description = 'Show the difference between env files'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var ReaderInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $reader; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Create a new command instance. |
|
38
|
|
|
* |
|
39
|
|
|
* @param ReaderInterface $reader |
|
40
|
|
|
*/ |
|
41
|
7 |
|
public function __construct(ReaderInterface $reader) |
|
42
|
|
|
{ |
|
43
|
7 |
|
parent::__construct(); |
|
44
|
7 |
|
$this->reader = $reader; |
|
45
|
7 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Execute the console command. |
|
49
|
|
|
* |
|
50
|
|
|
* @return mixed |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function handle() |
|
53
|
|
|
{ |
|
54
|
1 |
|
list($src, $dest) = $this->getSrcAndDest(); |
|
55
|
|
|
|
|
56
|
1 |
|
$envValues = $this->reader->read($dest); |
|
57
|
1 |
|
$exampleValues = $this->reader->read($src); |
|
58
|
|
|
|
|
59
|
1 |
|
$keys = array_unique(array_merge(array_keys($envValues), array_keys($exampleValues))); |
|
60
|
1 |
|
sort($keys); |
|
61
|
|
|
|
|
62
|
1 |
|
$header = ["Key", basename($dest), basename($src)]; |
|
63
|
1 |
|
$lines = []; |
|
64
|
1 |
|
foreach ($keys as $key) { |
|
65
|
1 |
|
$envVal = isset($envValues[$key]) ? $envValues[$key] : '<error>NOT FOUND</error>'; |
|
66
|
1 |
|
$exampleVal = isset($exampleValues[$key]) ? $exampleValues[$key] : '<error>NOT FOUND</error>'; |
|
67
|
1 |
|
$lines[] = [$key, $envVal, $exampleVal]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
$this->table($header, $lines); |
|
71
|
1 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|