5 * Contains \Drupal\Console\Command\Generate\CommandCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Command\Shared\ExtensionTrait;
11 use Drupal\Console\Command\Shared\ServicesTrait;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Input\InputOption;
15 use Symfony\Component\Console\Command\Command;
16 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
17 use Drupal\Console\Command\Shared\ConfirmationTrait;
18 use Drupal\Console\Command\Shared\ModuleTrait;
19 use Drupal\Console\Generator\CommandGenerator;
20 use Drupal\Console\Core\Utils\StringConverter;
21 use Drupal\Console\Extension\Manager;
22 use Drupal\Console\Core\Style\DrupalStyle;
23 use Drupal\Console\Utils\Validator;
25 class CommandCommand extends Command
27 use ContainerAwareCommandTrait;
28 use ConfirmationTrait;
34 * @var CommandGenerator
41 protected $extensionManager;
49 * @var StringConverter
51 protected $stringConverter;
54 * CommandCommand constructor.
56 * @param CommandGenerator $generator
57 * @param Manager $extensionManager
58 * @param Validator $validator
59 * @param StringConverter $stringConverter
61 public function __construct(
62 CommandGenerator $generator,
63 Manager $extensionManager,
65 StringConverter $stringConverter
67 $this->generator = $generator;
68 $this->extensionManager = $extensionManager;
69 $this->validator = $validator;
70 $this->stringConverter = $stringConverter;
71 parent::__construct();
77 protected function configure()
80 ->setName('generate:command')
81 ->setDescription($this->trans('commands.generate.command.description'))
82 ->setHelp($this->trans('commands.generate.command.help'))
86 InputOption::VALUE_REQUIRED,
87 $this->trans('commands.common.options.extension')
92 InputOption::VALUE_REQUIRED,
93 $this->trans('commands.common.options.extension-type')
98 InputOption::VALUE_REQUIRED,
99 $this->trans('commands.generate.command.options.class')
104 InputOption::VALUE_REQUIRED,
105 $this->trans('commands.generate.command.options.name')
110 InputOption::VALUE_NONE,
111 $this->trans('commands.generate.command.options.container-aware')
116 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
117 $this->trans('commands.common.options.services')
124 protected function execute(InputInterface $input, OutputInterface $output)
126 $io = new DrupalStyle($input, $output);
128 $extension = $input->getOption('extension');
129 $extensionType = $input->getOption('extension-type');
130 $class = $input->getOption('class');
131 $name = $input->getOption('name');
132 $containerAware = $input->getOption('container-aware');
133 $services = $input->getOption('services');
134 $yes = $input->hasOption('yes')?$input->getOption('yes'):false;
136 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
137 if (!$this->confirmGeneration($io, $yes)) {
141 // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices
142 $build_services = $this->buildServices($services);
144 $this->generator->generate(
157 protected function interact(InputInterface $input, OutputInterface $output)
159 $io = new DrupalStyle($input, $output);
161 $extension = $input->getOption('extension');
163 $extension = $this->extensionQuestion($io, true, true);
164 $input->setOption('extension', $extension->getName());
165 $input->setOption('extension-type', $extension->getType());
168 $extensionType = $input->getOption('extension-type');
169 if (!$extensionType) {
170 $extensionType = $this->extensionTypeQuestion($io);
171 $input->setOption('extension-type', $extensionType);
174 $name = $input->getOption('name');
177 $this->trans('commands.generate.command.questions.name'),
178 sprintf('%s:default', $extension->getName())
180 $input->setOption('name', $name);
183 $class = $input->getOption('class');
186 $this->trans('commands.generate.command.questions.class'),
189 return $this->validator->validateCommandName($class);
192 $input->setOption('class', $class);
195 $containerAware = $input->getOption('container-aware');
196 if (!$containerAware) {
197 $containerAware = $io->confirm(
198 $this->trans('commands.generate.command.questions.container-aware'),
201 $input->setOption('container-aware', $containerAware);
204 if (!$containerAware) {
205 // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
206 $services = $this->servicesQuestion($io);
207 $input->setOption('services', $services);