-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathded
executable file
·61 lines (48 loc) · 1.45 KB
/
ded
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env php
<?php
declare(strict_types=1);
require __DIR__.'/../../autoload.php';
use jc21\CliTable;
use ChrisWhite\DotEnvDiff\Diff;
$firstEnvFile = $argv[1] ?? null;
$secondEnvFile = $argv[2] ?? null;
if ($firstEnvFile === null || $secondEnvFile === null) {
echo "\033[31mUsage: ded /path/to/first/.env /path/to/second/.env\n";
return;
}
if (!file_exists($argv[1])) {
echo "\033[31mFile {$argv[1]} does not exist.\n";
return;
}
if (!file_exists($argv[2])) {
echo "\033[31mFile {$argv[2]} does not exist.\n";
return;
}
$firstEnvPathInfo = pathinfo($firstEnvFile);
$secondEnvPathInfo = pathinfo($secondEnvFile);
$diff = new Diff;
$diffResult = $diff->diff(file_get_contents($firstEnvFile), file_get_contents($secondEnvFile));
if ($diffResult->envsAreIdentical()) {
echo "\033[32mEnvironment keys are identical!\n";
return;
}
$table = new CliTable;
$table->setTableColor('blue');
$table->setHeaderColor('cyan');
$table->addField($firstEnvPathInfo['basename'], md5($firstEnvFile));
$table->addField($secondEnvPathInfo['basename'], md5($secondEnvFile));
$tableData = [];
foreach ($diffResult->onlyInFirstEnv() as $result) {
$tableData[] = [
md5($firstEnvFile) => $result,
md5($secondEnvFile) => ''
];
}
foreach ($diffResult->onlyInSecondEnv() as $result) {
$tableData[] = [
md5($firstEnvFile) => '',
md5($secondEnvFile) => $result
];
}
$table->injectData($tableData);
$table->display();