diff --git a/module/CLI/config/cli.config.php b/module/CLI/config/cli.config.php index 8bd88607..53a5172b 100644 --- a/module/CLI/config/cli.config.php +++ b/module/CLI/config/cli.config.php @@ -17,6 +17,7 @@ return [ Command\Api\GenerateKeyCommand::class, Command\Api\DisableKeyCommand::class, Command\Api\ListKeysCommand::class, + Command\Tag\ListTagsCommand::class, ] ], diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index 00e56607..6795852d 100644 --- a/module/CLI/config/dependencies.config.php +++ b/module/CLI/config/dependencies.config.php @@ -21,6 +21,7 @@ return [ Command\Api\GenerateKeyCommand::class => AnnotatedFactory::class, Command\Api\DisableKeyCommand::class => AnnotatedFactory::class, Command\Api\ListKeysCommand::class => AnnotatedFactory::class, + Command\Tag\ListTagsCommand::class => AnnotatedFactory::class, ], ], diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php new file mode 100644 index 00000000..442706fd --- /dev/null +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -0,0 +1,69 @@ +tagService = $tagService; + $this->translator = $translator; + } + + protected function configure() + { + $this + ->setName('tag:list') + ->setDescription('Lists existing tags'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $table = new Table($output); + $table->setHeaders([$this->translator->translate('Name')]) + ->setRows($this->getTagsRows()); + + $table->render(); + } + + private function getTagsRows() + { + $tags = $this->tagService->listTags(); + if (empty($tags)) { + return [[$this->translator->translate('No tags yet')]]; + } + + return array_map(function (Tag $tag) { + return [$tag->getName()]; + }, $tags); + } +} diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index 91cb5a72..5bc06ec5 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -29,6 +29,6 @@ class TagService implements TagServiceInterface */ public function listTags() { - return $this->em->getRepository(Tag::class)->findBy([], ['name' => 'DESC']); + return $this->em->getRepository(Tag::class)->findBy([], ['name' => 'ASC']); } }