From d8d66cbbde32a8bde1d86370277658eb9101130a Mon Sep 17 00:00:00 2001 From: msamgan Date: Mon, 7 Oct 2024 21:26:37 -0400 Subject: [PATCH 1/2] added progress bar. --- src/Commands/LaravelEnvKeysCheckerCommand.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Commands/LaravelEnvKeysCheckerCommand.php b/src/Commands/LaravelEnvKeysCheckerCommand.php index ef277e9..c8e11e7 100644 --- a/src/Commands/LaravelEnvKeysCheckerCommand.php +++ b/src/Commands/LaravelEnvKeysCheckerCommand.php @@ -5,6 +5,7 @@ use Illuminate\Console\Command; use function Laravel\Prompts\confirm; +use function Laravel\Prompts\progress; use function Laravel\Prompts\table; use Msamgan\LaravelEnvKeysChecker\Actions\AddKeys; @@ -46,9 +47,13 @@ public function handle(GetKeys $getKeys, CheckKeys $checkKeys, AddKeys $addKeys) $keys = $getKeys->handle(files: $envFiles); $missingKeys = collect(); - $keys->each(function ($keyData) use ($envFiles, $missingKeys, $checkKeys) { - $checkKeys->handle(keyData: $keyData, envFiles: $envFiles, missingKeys: $missingKeys); - }); + + progress( + label: 'Checking keys...', + steps: $keys, + callback: fn ($key) => $checkKeys->handle(keyData: $key, envFiles: $envFiles, missingKeys: $missingKeys), + hint: 'It won\'t take long.' + ); if ($missingKeys->isEmpty()) { $this->info('=> All keys are present in across all .env files.'); @@ -84,5 +89,6 @@ public function handle(GetKeys $getKeys, CheckKeys $checkKeys, AddKeys $addKeys) } return self::FAILURE; + } } From d6744a075fbf8ddecd67c85b20ff15e8e3299abb Mon Sep 17 00:00:00 2001 From: msamgan Date: Tue, 8 Oct 2024 10:52:20 -0400 Subject: [PATCH 2/2] Progress Bar in the command. --- src/Commands/LaravelEnvKeysCheckerCommand.php | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Commands/LaravelEnvKeysCheckerCommand.php b/src/Commands/LaravelEnvKeysCheckerCommand.php index c8e11e7..10df0f0 100644 --- a/src/Commands/LaravelEnvKeysCheckerCommand.php +++ b/src/Commands/LaravelEnvKeysCheckerCommand.php @@ -3,8 +3,11 @@ namespace Msamgan\LaravelEnvKeysChecker\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Collection; use function Laravel\Prompts\confirm; +use function Laravel\Prompts\error; +use function Laravel\Prompts\info; use function Laravel\Prompts\progress; use function Laravel\Prompts\table; @@ -29,13 +32,17 @@ public function handle(GetKeys $getKeys, CheckKeys $checkKeys, AddKeys $addKeys) $autoAddStrategy = $autoAddOption ?: config('env-keys-checker.auto_add', 'ask'); if (! in_array($autoAddStrategy, $autoAddAvailableOptions)) { - $this->error('!! Invalid auto add option provided. Available options are: ' . implode(', ', $autoAddAvailableOptions)); + $this->showFailureInfo( + message: 'Invalid auto add option provided. Available options are: ' . implode(', ', $autoAddAvailableOptions) + ); return self::FAILURE; } if (empty($envFiles)) { - $this->error('!! No .env files found.'); + $this->showFailureInfo( + message: 'No .env files found.' + ); return self::FAILURE; } @@ -56,27 +63,22 @@ public function handle(GetKeys $getKeys, CheckKeys $checkKeys, AddKeys $addKeys) ); if ($missingKeys->isEmpty()) { - $this->info('=> All keys are present in across all .env files.'); + $this->showSuccessInfo( + message: 'All keys are present in all .env files.' + ); return self::SUCCESS; } - table( - headers: ['Line', 'Key', 'Is missing in'], - rows: $missingKeys->map(function ($missingKey) { - return [ - $missingKey['line'], - $missingKey['key'], - $missingKey['envFile'], - ]; - })->toArray() - ); + $this->showMissingKeysTable($missingKeys); if ($autoAddStrategy === 'ask') { $confirmation = confirm('Do you want to add the missing keys to the .env files?'); if ($confirmation) { $addKeys->handle(missingKeys: $missingKeys); + + $this->showSuccessInfo('All missing keys have been added to the .env files.'); } return self::SUCCESS; @@ -91,4 +93,28 @@ public function handle(GetKeys $getKeys, CheckKeys $checkKeys, AddKeys $addKeys) return self::FAILURE; } + + private function showSuccessInfo(string $message): void + { + info(' => ' . $message); + } + + private function showFailureInfo(string $message): void + { + error(' !! ' . $message); + } + + private function showMissingKeysTable(Collection $missingKeys): void + { + table( + headers: ['Line', 'Key', 'Is missing in'], + rows: $missingKeys->map(function ($missingKey) { + return [ + $missingKey['line'], + $missingKey['key'], + $missingKey['envFile'], + ]; + })->toArray() + ); + } }