diff --git a/src/CLI/Command/ListShortcodesCommand.php b/src/CLI/Command/ListShortcodesCommand.php index 7df61588..ac85d50f 100644 --- a/src/CLI/Command/ListShortcodesCommand.php +++ b/src/CLI/Command/ListShortcodesCommand.php @@ -2,19 +2,22 @@ namespace Acelaya\UrlShortener\CLI\Command; use Acelaya\UrlShortener\Paginator\Adapter\PaginableRepositoryAdapter; +use Acelaya\UrlShortener\Paginator\Util\PaginatorUtilsTrait; use Acelaya\UrlShortener\Service\ShortUrlService; use Acelaya\UrlShortener\Service\ShortUrlServiceInterface; use Acelaya\ZsmAnnotatedServices\Annotation\Inject; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Helper\Table; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; class ListShortcodesCommand extends Command { + use PaginatorUtilsTrait; + /** * @var ShortUrlServiceInterface */ @@ -36,9 +39,10 @@ class ListShortcodesCommand extends Command { $this->setName('shortcode:list') ->setDescription('List all short URLs') - ->addArgument( + ->addOption( 'page', - InputArgument::OPTIONAL, + 'p', + InputOption::VALUE_OPTIONAL, sprintf('The first page to list (%s items per page)', PaginableRepositoryAdapter::ITEMS_PER_PAGE), 1 ); @@ -46,7 +50,7 @@ class ListShortcodesCommand extends Command public function execute(InputInterface $input, OutputInterface $output) { - $page = intval($input->getArgument('page')); + $page = intval($input->getOption('page')); /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); @@ -66,7 +70,15 @@ class ListShortcodesCommand extends Command } $table->render(); - $question = new ConfirmationQuestion('Continue with next page? (y/N) ', false); - } while ($helper->ask($input, $output, $question)); + if ($this->isLastPage($result)) { + $continue = false; + $output->writeln('You have reached last page'); + } else { + $continue = $helper->ask($input, $output, new ConfirmationQuestion( + sprintf('Continue with page %s? (y/N) ', $page), + false + )); + } + } while ($continue); } } diff --git a/src/Middleware/Rest/ListShortcodesMiddleware.php b/src/Middleware/Rest/ListShortcodesMiddleware.php index 6b74241c..99d82454 100644 --- a/src/Middleware/Rest/ListShortcodesMiddleware.php +++ b/src/Middleware/Rest/ListShortcodesMiddleware.php @@ -1,7 +1,7 @@ getCurrentPageNumber() >= $paginator->count(); + } }