Added current page message in list short urls CLI command

This commit is contained in:
Alejandro Celaya 2018-12-08 12:16:39 +01:00
parent bb40d84212
commit 1983fc9b67
3 changed files with 12 additions and 3 deletions

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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());
}
}