diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 32791f93..b7bbaf3a 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -73,6 +73,11 @@ class ListShortUrlsCommand extends Command ) ->addOption( 'tags', + mode: InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + description: '[DEPRECATED] Use --tag instead', + ) + ->addOption( + 'tag', 't', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A list of tags that short URLs need to include.', @@ -84,7 +89,7 @@ class ListShortUrlsCommand extends Command description: 'If --tags is provided, returns only short URLs including ALL of them', ) ->addOption( - 'exclude-tags', + 'exclude-tag', 'et', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A list of tags that short URLs should not have.', @@ -92,7 +97,7 @@ class ListShortUrlsCommand extends Command ->addOption( 'exclude-tags-all', mode: InputOption::VALUE_NONE, - description: 'If --exclude-tags is provided, returns only short URLs not including ANY of them', + description: 'If --exclude-tag is provided, returns only short URLs not including ANY of them', ) ->addOption( 'exclude-max-visits-reached', @@ -150,13 +155,13 @@ class ListShortUrlsCommand extends Command $domain = $input->getOption('domain'); // FIXME DEPRECATED Remove support for comma-separated tags in next major release - $tags = $input->getOption('tags'); + $tags = [...$input->getOption('tag'), ...$input->getOption('tags')]; $tags = flatten(map($tags, static fn (string $tag) => explode(',', $tag))); $tagsMode = $input->getOption('tags-all') === true || $input->getOption('including-all-tags') === true ? TagsMode::ALL->value : TagsMode::ANY->value; - $excludeTags = $input->getOption('exclude-tags'); + $excludeTags = $input->getOption('exclude-tag'); $excludeTagsMode = $input->getOption('exclude-tags-all') === true ? TagsMode::ALL->value : TagsMode::ANY->value; $all = $input->getOption('all'); diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 0a7f9aa0..755d179c 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -25,8 +25,6 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; use Symfony\Component\Console\Tester\CommandTester; -use function explode; - class ListShortUrlsCommandTest extends TestCase { private CommandTester $commandTester; @@ -209,6 +207,8 @@ class ListShortUrlsCommandTest extends TestCase string $tagsMode, string|null $startDate = null, string|null $endDate = null, + array $excludeTags = [], + string $excludeTagsMode = TagsMode::ANY->value, ): void { $this->shortUrlService->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([ 'page' => $page, @@ -217,6 +217,8 @@ class ListShortUrlsCommandTest extends TestCase 'tagsMode' => $tagsMode, 'startDate' => $startDate !== null ? Chronos::parse($startDate)->toAtomString() : null, 'endDate' => $endDate !== null ? Chronos::parse($endDate)->toAtomString() : null, + 'excludeTags' => $excludeTags, + 'excludeTagsMode' => $excludeTagsMode, ]))->willReturn(new Paginator(new ArrayAdapter([]))); $this->commandTester->setInputs(['n']); @@ -230,10 +232,10 @@ class ListShortUrlsCommandTest extends TestCase yield [['--including-all-tags' => true], 1, null, [], TagsMode::ALL->value]; yield [['--search-term' => $searchTerm = 'search this'], 1, $searchTerm, [], TagsMode::ANY->value]; yield [ - ['--page' => $page = 3, '--search-term' => $searchTerm = 'search this', '--tags' => $tags = 'foo,bar'], + ['--page' => $page = 3, '--search-term' => $searchTerm = 'search this', '--tag' => $tags = ['foo', 'bar']], $page, $searchTerm, - explode(',', $tags), + $tags, TagsMode::ANY->value, ]; yield [ @@ -262,6 +264,17 @@ class ListShortUrlsCommandTest extends TestCase $startDate, $endDate, ]; + yield [ + ['--exclude-tag' => ['foo', 'bar'], '--exclude-tags-all' => true], + 1, + null, + [], + TagsMode::ANY->value, + null, + null, + ['foo', 'bar'], + TagsMode::ALL->value, + ]; } #[Test, DataProvider('provideOrderBy')]