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;
24 use Drupal\Console\Utils\Site;
26 class CommandCommand extends Command
28 use ContainerAwareCommandTrait;
29 use ConfirmationTrait;
35 * @var CommandGenerator
42 protected $extensionManager;
50 * @var StringConverter
52 protected $stringConverter;
60 * CommandCommand constructor.
62 * @param CommandGenerator $generator
63 * @param Manager $extensionManager
64 * @param Validator $validator
65 * @param StringConverter $stringConverter
68 public function __construct(
69 CommandGenerator $generator,
70 Manager $extensionManager,
72 StringConverter $stringConverter,
75 $this->generator = $generator;
76 $this->extensionManager = $extensionManager;
77 $this->validator = $validator;
78 $this->stringConverter = $stringConverter;
80 parent::__construct();
86 protected function configure()
89 ->setName('generate:command')
90 ->setDescription($this->trans('commands.generate.command.description'))
91 ->setHelp($this->trans('commands.generate.command.help'))
95 InputOption::VALUE_REQUIRED,
96 $this->trans('commands.common.options.extension')
101 InputOption::VALUE_REQUIRED,
102 $this->trans('commands.common.options.extension-type')
107 InputOption::VALUE_REQUIRED,
108 $this->trans('commands.generate.command.options.class')
113 InputOption::VALUE_REQUIRED,
114 $this->trans('commands.generate.command.options.name')
119 InputOption::VALUE_NONE,
120 $this->trans('commands.generate.command.options.container-aware')
125 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
126 $this->trans('commands.common.options.services')
133 protected function execute(InputInterface $input, OutputInterface $output)
135 $io = new DrupalStyle($input, $output);
137 $extension = $input->getOption('extension');
138 $extensionType = $input->getOption('extension-type');
139 $class = $input->getOption('class');
140 $name = $input->getOption('name');
141 $containerAware = $input->getOption('container-aware');
142 $services = $input->getOption('services');
143 $yes = $input->hasOption('yes')?$input->getOption('yes'):false;
145 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
146 if (!$this->confirmGeneration($io, $yes)) {
150 // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices
151 $build_services = $this->buildServices($services);
153 $this->generator->generate(
162 $this->site->removeCachedServicesFile();
170 protected function interact(InputInterface $input, OutputInterface $output)
172 $io = new DrupalStyle($input, $output);
174 $extension = $input->getOption('extension');
176 $extension = $this->extensionQuestion($io, true, true);
177 $input->setOption('extension', $extension->getName());
178 $input->setOption('extension-type', $extension->getType());
181 $extensionType = $input->getOption('extension-type');
182 if (!$extensionType) {
183 $extensionType = $this->extensionTypeQuestion($io);
184 $input->setOption('extension-type', $extensionType);
187 $name = $input->getOption('name');
190 $this->trans('commands.generate.command.questions.name'),
191 sprintf('%s:default', $extension->getName())
193 $input->setOption('name', $name);
196 $class = $input->getOption('class');
199 $this->trans('commands.generate.command.questions.class'),
202 return $this->validator->validateCommandName($class);
205 $input->setOption('class', $class);
208 $containerAware = $input->getOption('container-aware');
209 if (!$containerAware) {
210 $containerAware = $io->confirm(
211 $this->trans('commands.generate.command.questions.container-aware'),
214 $input->setOption('container-aware', $containerAware);
217 if (!$containerAware) {
218 // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
219 $services = $this->servicesQuestion($io);
220 $input->setOption('services', $services);