Skip to content

Commit

Permalink
Merge pull request #5135 from neos/feature/improve-site-list-command
Browse files Browse the repository at this point in the history
FEATURE: Improve site:list command
  • Loading branch information
Sebobo authored Jun 11, 2024
2 parents ff2ea46 + 8810907 commit 0b49ae9
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions Neos.Neos/Classes/Command/SiteCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\Log\ThrowableStorageInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Package\PackageManager;
Expand Down Expand Up @@ -332,47 +333,23 @@ public function pruneCommand($siteNode)
* List available sites
*
* @return void
* @throws StopCommandException
*/
public function listCommand()
public function listCommand(): void
{
$sites = $this->siteRepository->findAll();

if ($sites->count() === 0) {
$this->outputLine('No sites available');
$this->quit(0);
$this->quit();
}

$longestSiteName = 4;
$longestNodeName = 9;
$longestSiteResource = 17;
$availableSites = [];

$tableRows = [];
$tableHeaderRows = ['Name', 'Node name', 'Resource package', 'Status'];
foreach ($sites as $site) {
/** @var Site $site */
array_push($availableSites, [
'name' => $site->getName(),
'nodeName' => $site->getNodeName(),
'siteResourcesPackageKey' => $site->getSiteResourcesPackageKey(),
'status' => ($site->getState() === SITE::STATE_ONLINE) ? 'online' : 'offline'
]);
if (strlen($site->getName()) > $longestSiteName) {
$longestSiteName = strlen($site->getName());
}
if (strlen($site->getNodeName()) > $longestNodeName) {
$longestNodeName = strlen($site->getNodeName());
}
if (strlen($site->getSiteResourcesPackageKey()) > $longestSiteResource) {
$longestSiteResource = strlen($site->getSiteResourcesPackageKey());
}
}

$this->outputLine();
$this->outputLine(' ' . str_pad('Name', $longestSiteName + 15) . str_pad('Node name', $longestNodeName + 15) . str_pad('Resources package', $longestSiteResource + 15) . 'Status ');
$this->outputLine(str_repeat('-', $longestSiteName + $longestNodeName + $longestSiteResource + 7 + 15 + 15 + 15 + 2));
foreach ($availableSites as $site) {
$this->outputLine(' ' . str_pad($site['name'], $longestSiteName + 15) . str_pad($site['nodeName'], $longestNodeName + 15) . str_pad($site['siteResourcesPackageKey'], $longestSiteResource + 15) . $site['status']);
$siteStatus = ($site->getState() === SITE::STATE_ONLINE) ? 'online' : 'offline';
$tableRows[] = [$site->getName(), $site->getNodeName(), $site->getSiteResourcesPackageKey(), $siteStatus];
}
$this->outputLine();
$this->output->outputTable($tableRows, $tableHeaderRows);
}

/**
Expand Down

0 comments on commit 0b49ae9

Please sign in to comment.