namespace Drupal\Console\Command\Create;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
use Drupal\Console\Utils\Create\VocabularyData;
-use Drupal\Console\Core\Style\DrupalStyle;
/**
* Class VocabulariesCommand
*/
class VocabulariesCommand extends Command
{
- use CommandTrait;
-
/**
* @var VocabularyData
*/
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.create.vocabularies.options.name-words')
- );
+ )->setAliases(['crv']);
}
/**
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
$limit = $input->getOption('limit');
if (!$limit) {
- $limit = $io->ask(
+ $limit = $this->getIo()->ask(
$this->trans('commands.create.vocabularies.questions.limit'),
25
);
$nameWords = $input->getOption('name-words');
if (!$nameWords) {
- $nameWords = $io->ask(
+ $nameWords = $this->getIo()->ask(
$this->trans('commands.create.vocabularies.questions.name-words'),
5
);
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
$limit = $input->getOption('limit')?:25;
$nameWords = $input->getOption('name-words')?:5;
- $vocabularies = $this->vocabularyData->create(
+ $result = $this->vocabularyData->create(
$limit,
$nameWords
);
$this->trans('commands.create.vocabularies.messages.name'),
];
- if (isset($vocabularies['success'])) {
- $io->table($tableHeader, $vocabularies['success']);
+ if (isset($result['success'])) {
+ $this->getIo()->table($tableHeader, $result['success']);
- $io->success(
+ $this->getIo()->success(
sprintf(
$this->trans('commands.create.vocabularies.messages.created-terms'),
- $limit
- )
- );
- } else {
- $io->error(
- sprintf(
- $this->trans('commands.create.vocabularies.messages.error'),
- $vocabularies['error'][0]['error']
+ count($result['success'])
)
);
}
+ if (isset($result['error'])) {
+ foreach ($result['error'] as $error) {
+ $this->getIo()->error(
+ sprintf(
+ $this->trans('commands.create.vocabularies.messages.error'),
+ $error
+ )
+ );
+ }
+ }
+
return 0;
}
}