mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-27 16:26:37 +03:00
Improved and simplified CreateTagCommand thanks to SymfonyStyle
This commit is contained in:
parent
a60c45ca4d
commit
09b161304c
2 changed files with 6 additions and 13 deletions
|
@ -8,6 +8,7 @@ use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Zend\I18n\Translator\TranslatorInterface;
|
use Zend\I18n\Translator\TranslatorInterface;
|
||||||
|
|
||||||
class CreateTagCommand extends Command
|
class CreateTagCommand extends Command
|
||||||
|
@ -45,19 +46,15 @@ class CreateTagCommand extends Command
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
$tagNames = $input->getOption('name');
|
$tagNames = $input->getOption('name');
|
||||||
|
|
||||||
if (empty($tagNames)) {
|
if (empty($tagNames)) {
|
||||||
$output->writeln(sprintf(
|
$io->warning($this->translator->translate('You have to provide at least one tag name'));
|
||||||
'<comment>%s</comment>',
|
|
||||||
$this->translator->translate('You have to provide at least one tag name')
|
|
||||||
));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->tagService->createTags($tagNames);
|
$this->tagService->createTags($tagNames);
|
||||||
$output->writeln($this->translator->translate('Created tags') . sprintf(': ["<info>%s</info>"]', implode(
|
$io->success($this->translator->translate('Tags properly created'));
|
||||||
'</info>", "<info>',
|
|
||||||
$tagNames
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,6 @@ use Zend\I18n\Translator\Translator;
|
||||||
|
|
||||||
class CreateTagCommandTest extends TestCase
|
class CreateTagCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var CreateTagCommand
|
|
||||||
*/
|
|
||||||
private $command;
|
|
||||||
/**
|
/**
|
||||||
* @var CommandTester
|
* @var CommandTester
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +59,7 @@ class CreateTagCommandTest extends TestCase
|
||||||
]);
|
]);
|
||||||
$output = $this->commandTester->getDisplay();
|
$output = $this->commandTester->getDisplay();
|
||||||
|
|
||||||
$this->assertContains(sprintf('Created tags: ["%s"]', implode('", "', $tagNames)), $output);
|
$this->assertContains('Tags properly created', $output);
|
||||||
$createTags->shouldHaveBeenCalled();
|
$createTags->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue