From cf49393ef2d183ad9b74d0d63176a0d34e5ca911 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Apr 2023 11:19:05 +0200 Subject: [PATCH] Add --show-domain flag to list short URLs command --- .../Command/ShortUrl/ListShortUrlsCommand.php | 10 +++++++ .../ShortUrl/ListShortUrlsCommandTest.php | 29 ++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 7a9c77af..9202957b 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -102,6 +102,12 @@ class ListShortUrlsCommand extends Command InputOption::VALUE_NONE, 'Whether to display the tags or not.', ) + ->addOption( + 'show-domain', + null, + InputOption::VALUE_NONE, + 'Whether to display the domain or not. Those belonging to default domain will have value "DEFAULT".', + ) ->addOption( 'show-api-key', 'k', @@ -217,6 +223,10 @@ class ListShortUrlsCommand extends Command if ($input->getOption('show-tags')) { $columnsMap['Tags'] = static fn (array $shortUrl): string => implode(', ', $shortUrl['tags']); } + if ($input->getOption('show-domain')) { + $columnsMap['Domain'] = static fn (array $_, ShortUrl $shortUrl): string => + $shortUrl->getDomain()?->authority ?? 'DEFAULT'; + } if ($input->getOption('show-api-key')) { $columnsMap['API Key'] = static fn (array $_, ShortUrl $shortUrl): string => $shortUrl->authorApiKey()?->__toString() ?? ''; diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 52d1eeb3..d81172ed 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -144,13 +144,19 @@ class ListShortUrlsCommandTest extends TestCase yield 'tags only' => [ ['--show-tags' => true], ['| Tags ', '| foo, bar, baz'], - ['| API Key ', '| API Key Name |', $key, '| my api key'], + ['| API Key ', '| API Key Name |', $key, '| my api key', '| Domain', '| DEFAULT'], + $apiKey, + ]; + yield 'domain only' => [ + ['--show-domain' => true], + ['| Domain', '| DEFAULT'], + ['| Tags ', '| foo, bar, baz', '| API Key ', '| API Key Name |', $key, '| my api key'], $apiKey, ]; yield 'api key only' => [ ['--show-api-key' => true], ['| API Key ', $key], - ['| Tags ', '| foo, bar, baz', '| API Key Name |', '| my api key'], + ['| Tags ', '| foo, bar, baz', '| API Key Name |', '| my api key', '| Domain', '| DEFAULT'], $apiKey, ]; yield 'api key name only' => [ @@ -165,9 +171,24 @@ class ListShortUrlsCommandTest extends TestCase ['| API Key Name |', '| my api key'], $apiKey, ]; + yield 'tags and domain' => [ + ['--show-tags' => true, '--show-domain' => true], + ['| Tags ', '| foo, bar, baz', '| Domain', '| DEFAULT'], + ['| API Key Name |', '| my api key'], + $apiKey, + ]; yield 'all' => [ - ['--show-tags' => true, '--show-api-key' => true, '--show-api-key-name' => true], - ['| API Key ', '| Tags ', '| API Key Name |', '| foo, bar, baz', $key, '| my api key'], + ['--show-tags' => true, '--show-domain' => true, '--show-api-key' => true, '--show-api-key-name' => true], + [ + '| API Key ', + '| Tags ', + '| API Key Name |', + '| foo, bar, baz', + $key, + '| my api key', + '| Domain', + '| DEFAULT', + ], [], $apiKey, ];