diff --git a/Neos.Neos/Classes/Command/SiteCommandController.php b/Neos.Neos/Classes/Command/SiteCommandController.php index 640902a44c8..f5308436721 100644 --- a/Neos.Neos/Classes/Command/SiteCommandController.php +++ b/Neos.Neos/Classes/Command/SiteCommandController.php @@ -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; @@ -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); } /**