From 632d2dfe1584af315c5a00cc7a7d974996ae1ed1 Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Mon, 15 Jul 2024 17:46:45 +0200 Subject: [PATCH] feat: added repository:list command --- app/Console/Commands/ListRepositories.php | 41 +++++++++++++++++++++++ tests/Feature/CommandLineTest.php | 13 ++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/ListRepositories.php diff --git a/app/Console/Commands/ListRepositories.php b/app/Console/Commands/ListRepositories.php new file mode 100644 index 0000000..4b56d1b --- /dev/null +++ b/app/Console/Commands/ListRepositories.php @@ -0,0 +1,41 @@ +table( + ['Name', 'Delay (in days)', 'Repo Frozen', 'Serving Directory'], + Repository::all()->map(function (Repository $repository) { + return [ + $repository->name, + $repository->delay, + $repository->freeze ? 'Yes' : 'No', + $repository->getStablePath(), + ]; + }) + ); + } +} diff --git a/tests/Feature/CommandLineTest.php b/tests/Feature/CommandLineTest.php index d2f2ae6..b114c8c 100644 --- a/tests/Feature/CommandLineTest.php +++ b/tests/Feature/CommandLineTest.php @@ -3,7 +3,6 @@ use App\Jobs\SyncRepository; use App\Models\Repository; use Illuminate\Support\Facades\Queue; - use function Pest\Laravel\artisan; use function Pest\Laravel\assertDatabaseHas; @@ -31,3 +30,15 @@ assertDatabaseHas('repositories', $repository->toArray()); Queue::assertPushed(SyncRepository::class); }); + +it('can list repositories', function () { + $repositories = Repository::factory()->create([ + 'name' => 'test', + 'delay' => 1, + ]); + artisan('repository:list') + ->expectsTable( + ['Name', 'Delay (in days)', 'Repo Frozen', 'Serving Directory'], + [['test', 1, 'No', 'snapshots/test/']], + ); +});