Skip to content

Commit

Permalink
add custom progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed May 9, 2024
1 parent 2895b96 commit d129b82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"php": "^8.1",
"illuminate/contracts": "^10.0|^11.0",
"laravel/helpers": "^1.7",
"spatie/emoji": "^4.1",
"spatie/laravel-package-tools": "^1.14.0",
"spatie/once": "^3.1"
},
Expand Down
26 changes: 24 additions & 2 deletions src/Commands/UpdatePermanentCachesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Vormkracht10\PermanentCache\Commands;

use Illuminate\Console\Command;
use ReflectionClass;
use Symfony\Component\Console\Helper\ProgressBar;
use Vormkracht10\PermanentCache\Facades\PermanentCache;

class UpdatePermanentCachesCommand extends Command
Expand All @@ -26,8 +28,28 @@ class UpdatePermanentCachesCommand extends Command
*/
public function handle()
{
$caches = PermanentCache::configuredCaches();
$caches = collect(
PermanentCache::configuredCaches()
);

$this->withProgressBar($caches, fn ($cache) => $cache->update());
ProgressBar::setFormatDefinition('custom', ' %current%/%max% [%bar%] %message%');

$progressBar = $this->output->createProgressBar($caches->count());

$progressBar->setFormat('custom');

$progressBar->setMessage('Starting...');

$progressBar->start();

$caches->each(function ($cache) use ($progressBar) {
$cache->update();

$progressBar->setMessage('Updating: '.(new ReflectionClass($cache))->getName());
$progressBar->advance();
});

$progressBar->setMessage('Finished!');
$progressBar->finish();
}
}

0 comments on commit d129b82

Please sign in to comment.