1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-15 17:04:03 +00:00
tenancy/src/Commands/TenantList.php
Jori Stein e4f5b92485
[4.x] Update commands CLI outputs (#968)
* Using laravel components

* Ensure commands returns success

* update tests

* clean

* bump EndBug version

* Update ci.yml

* Update ci.yml

* Update ci.yml

* revert CI changes

* Update ci.yml

* Update ci.yml

* Update ci.yml

* revert CI changes to it's original state

* fix typos, improve code

* improve Install & TenantList commands

* php-cs-fixer

* type GitHub properly

Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
2022-10-18 19:11:57 +02:00

49 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Stancl\Tenancy\Contracts\Tenant;
class TenantList extends Command
{
protected $signature = 'tenants:list';
protected $description = 'List tenants.';
public function handle(): int
{
$tenants = tenancy()->query()->cursor();
$this->components->info("Listing {$tenants->count()} tenants.");
foreach ($tenants as $tenant) {
/** @var Model&Tenant $tenant */
$this->components->twoColumnDetail($this->tenantCLI($tenant), $this->domainsCLI($tenant->domains));
}
$this->newLine();
return 0;
}
/** Generate the visual CLI output for the tenant name. */
protected function tenantCLI(Model&Tenant $tenant): string
{
return "<fg=yellow>{$tenant->getTenantKeyName()}: {$tenant->getTenantKey()}</>";
}
/** Generate the visual CLI output for the domain names. */
protected function domainsCLI(?Collection $domains): ?string
{
if (! $domains) {
return null;
}
return "<fg=blue;options=bold>{$domains->pluck('domain')->implode(' / ')}</>";
}
}