From 1983fc9b67d5890dab6daf95c494fd1489cb00ff Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 8 Dec 2018 12:16:39 +0100 Subject: [PATCH] Added current page message in list short urls CLI command --- module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php | 5 ++++- module/Common/src/Console/ShlinkTable.php | 4 ++-- module/Common/src/Paginator/Util/PaginatorUtilsTrait.php | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index f1362cd8..a5e83c85 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -126,7 +126,10 @@ class ListShortUrlsCommand extends Command $rows[] = array_values($shortUrl); } - ShlinkTable::fromOutput($output)->render($headers, $rows); + ShlinkTable::fromOutput($output)->render($headers, $rows, $this->formatCurrentPageMessage( + $result, + 'Page %s of %s' + )); return $result; } diff --git a/module/Common/src/Console/ShlinkTable.php b/module/Common/src/Console/ShlinkTable.php index 6530b99a..1ded8334 100644 --- a/module/Common/src/Console/ShlinkTable.php +++ b/module/Common/src/Console/ShlinkTable.php @@ -24,7 +24,7 @@ final class ShlinkTable return new self(new Table($output)); } - public function render(array $headers, array $rows, ?string $headerTitle = null, ?string $footerTitle = null): void + public function render(array $headers, array $rows, ?string $footerTitle = null, ?string $headerTitle = null): void { $style = Table::getStyleDefinition(self::DEFAULT_STYLE_NAME); $style->setFooterTitleFormat(self::TABLE_TITLE_STYLE) @@ -34,8 +34,8 @@ final class ShlinkTable $table->setStyle($style) ->setHeaders($headers) ->setRows($rows) - ->setHeaderTitle($headerTitle) ->setFooterTitle($footerTitle) + ->setHeaderTitle($headerTitle) ->render(); } } diff --git a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php index 85fcc861..c031db21 100644 --- a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php +++ b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Paginator\Util; use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; +use function sprintf; use Zend\Paginator\Paginator; use Zend\Stdlib\ArrayUtils; use function array_map; @@ -39,4 +40,9 @@ trait PaginatorUtilsTrait { return $paginator->getCurrentPageNumber() >= $paginator->count(); } + + private function formatCurrentPageMessage(Paginator $paginator, string $pattern): string + { + return sprintf($pattern, $paginator->getCurrentPageNumber(), $paginator->count()); + } }