mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-27 16:26:37 +03:00
Created ListTagsCommand
This commit is contained in:
parent
caf4fa7fdd
commit
1ba7fc81ac
4 changed files with 72 additions and 1 deletions
|
@ -17,6 +17,7 @@ return [
|
|||
Command\Api\GenerateKeyCommand::class,
|
||||
Command\Api\DisableKeyCommand::class,
|
||||
Command\Api\ListKeysCommand::class,
|
||||
Command\Tag\ListTagsCommand::class,
|
||||
]
|
||||
],
|
||||
|
||||
|
|
|
@ -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,
|
||||
],
|
||||
],
|
||||
|
||||
|
|
69
module/CLI/src/Command/Tag/ListTagsCommand.php
Normal file
69
module/CLI/src/Command/Tag/ListTagsCommand.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\CLI\Command\Tag;
|
||||
|
||||
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Service\Tag\TagService;
|
||||
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Zend\I18n\Translator\Translator;
|
||||
use Zend\I18n\Translator\TranslatorInterface;
|
||||
|
||||
class ListTagsCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var TagServiceInterface
|
||||
*/
|
||||
private $tagService;
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* ListTagsCommand constructor.
|
||||
* @param TagServiceInterface $tagService
|
||||
* @param TranslatorInterface $translator
|
||||
*
|
||||
* @DI\Inject({TagService::class, Translator::class})
|
||||
*/
|
||||
public function __construct(TagServiceInterface $tagService, TranslatorInterface $translator)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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);
|
||||
}
|
||||
}
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue