setName(self::NAME) ->setDescription('List all domains that have been ever used for some short URL') ->addOption( 'show-redirects', 'r', InputOption::VALUE_NONE, 'Will display an extra column with the information of the "not found" redirects for every domain.', ); } protected function execute(InputInterface $input, OutputInterface $output): ?int { $domains = $this->domainService->listDomains(); $showRedirects = $input->getOption('show-redirects'); $commonFields = ['Domain', 'Is default']; $table = $showRedirects ? ShlinkTable::withRowSeparators($output) : ShlinkTable::default($output); $table->render( $showRedirects ? [...$commonFields, '"Not found" redirects'] : $commonFields, map($domains, function (DomainItem $domain) use ($showRedirects) { $commonValues = [$domain->toString(), $domain->isDefault ? 'Yes' : 'No']; return $showRedirects ? [ ...$commonValues, $this->notFoundRedirectsToString($domain->notFoundRedirectConfig), ] : $commonValues; }), ); return ExitCode::EXIT_SUCCESS; } private function notFoundRedirectsToString(NotFoundRedirectConfigInterface $config): string { $baseUrl = $config->baseUrlRedirect() ?? 'N/A'; $regular404 = $config->regular404Redirect() ?? 'N/A'; $invalidShortUrl = $config->invalidShortUrlRedirect() ?? 'N/A'; return <<