Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / CommandCommand.php
index fc3a914b9613c09afe89f5ecf272210370441ff4..cca91d85974f825dd782b5ba1c6aac643a990987 100644 (file)
@@ -12,20 +12,17 @@ use Drupal\Console\Command\Shared\ServicesTrait;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
+use Drupal\Console\Core\Command\ContainerAwareCommand;
 use Drupal\Console\Command\Shared\ConfirmationTrait;
 use Drupal\Console\Command\Shared\ModuleTrait;
 use Drupal\Console\Generator\CommandGenerator;
 use Drupal\Console\Core\Utils\StringConverter;
 use Drupal\Console\Extension\Manager;
-use Drupal\Console\Core\Style\DrupalStyle;
 use Drupal\Console\Utils\Validator;
 use Drupal\Console\Utils\Site;
 
-class CommandCommand extends Command
+class CommandCommand extends ContainerAwareCommand
 {
-    use ContainerAwareCommandTrait;
     use ConfirmationTrait;
     use ServicesTrait;
     use ModuleTrait;
@@ -113,6 +110,18 @@ class CommandCommand extends Command
                 InputOption::VALUE_REQUIRED,
                 $this->trans('commands.generate.command.options.name')
             )
+            ->addOption(
+                'initialize',
+                null,
+                InputOption::VALUE_NONE,
+                $this->trans('commands.generate.command.options.initialize')
+            )
+            ->addOption(
+                'interact',
+                null,
+                InputOption::VALUE_NONE,
+                $this->trans('commands.generate.command.options.interact')
+            )
             ->addOption(
                 'container-aware',
                 null,
@@ -124,7 +133,14 @@ class CommandCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.common.options.services')
-            );
+            )
+            ->addOption(
+                'generator',
+                null,
+                InputOption::VALUE_NONE,
+                $this->trans('commands.generate.command.options.generator')
+            )
+            ->setAliases(['gco']);
     }
 
     /**
@@ -132,32 +148,41 @@ class CommandCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $extension = $input->getOption('extension');
         $extensionType = $input->getOption('extension-type');
-        $class = $input->getOption('class');
+        $class = $this->validator->validateCommandName($input->getOption('class'));
         $name = $input->getOption('name');
+        $initialize = $input->getOption('initialize');
+        $interact = $input->getOption('interact');
         $containerAware = $input->getOption('container-aware');
         $services = $input->getOption('services');
-        $yes = $input->hasOption('yes')?$input->getOption('yes'):false;
+        $generator = $input->getOption('generator');
 
-        // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
-        if (!$this->confirmGeneration($io, $yes)) {
+        // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
+        if (!$this->confirmOperation()) {
             return 1;
         }
 
         // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices
         $build_services = $this->buildServices($services);
 
-        $this->generator->generate(
-            $extension,
-            $extensionType,
-            $name,
-            $class,
-            $containerAware,
-            $build_services
-        );
+        $class_generator = null;
+        if ($generator) {
+            $class_generator = str_replace('Command', 'Generator', $class);
+        }
+
+        $this->generator->generate([
+            'extension' => $extension,
+            'extension_type' => $extensionType,
+            'name' => $name,
+            'initialize' => $initialize,
+            'interact' => $interact,
+            'class_name' => $class,
+            'container_aware' => $containerAware,
+            'services' => $build_services,
+            'class_generator' => $class_generator,
+            'generator' => $generator,
+        ]);
 
         $this->site->removeCachedServicesFile();
 
@@ -169,33 +194,49 @@ class CommandCommand extends Command
      */
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $extension = $input->getOption('extension');
         if (!$extension) {
-            $extension = $this->extensionQuestion($io, true, true);
+            $extension = $this->extensionQuestion(true, true);
             $input->setOption('extension', $extension->getName());
             $input->setOption('extension-type', $extension->getType());
         }
 
         $extensionType = $input->getOption('extension-type');
         if (!$extensionType) {
-            $extensionType = $this->extensionTypeQuestion($io);
+            $extensionType = $this->extensionTypeQuestion();
             $input->setOption('extension-type', $extensionType);
         }
 
         $name = $input->getOption('name');
         if (!$name) {
-            $name = $io->ask(
+            $name = $this->getIo()->ask(
                 $this->trans('commands.generate.command.questions.name'),
                 sprintf('%s:default', $extension->getName())
             );
             $input->setOption('name', $name);
         }
 
+        $initialize = $input->getOption('initialize');
+        if (!$initialize) {
+            $initialize = $this->getIo()->confirm(
+                $this->trans('commands.generate.command.questions.initialize'),
+                false
+            );
+            $input->setOption('initialize', $initialize);
+        }
+
+        $interact = $input->getOption('interact');
+        if (!$interact) {
+            $interact = $this->getIo()->confirm(
+                $this->trans('commands.generate.command.questions.interact'),
+                false
+            );
+            $input->setOption('interact', $interact);
+        }
+
         $class = $input->getOption('class');
         if (!$class) {
-            $class = $io->ask(
+            $class = $this->getIo()->ask(
                 $this->trans('commands.generate.command.questions.class'),
                 'DefaultCommand',
                 function ($class) {
@@ -207,7 +248,7 @@ class CommandCommand extends Command
 
         $containerAware = $input->getOption('container-aware');
         if (!$containerAware) {
-            $containerAware = $io->confirm(
+            $containerAware = $this->getIo()->confirm(
                 $this->trans('commands.generate.command.questions.container-aware'),
                 false
             );
@@ -216,8 +257,17 @@ class CommandCommand extends Command
 
         if (!$containerAware) {
             // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
-            $services = $this->servicesQuestion($io);
+            $services = $this->servicesQuestion();
             $input->setOption('services', $services);
         }
+
+        $generator = $input->getOption('generator');
+        if (!$generator) {
+            $generator = $this->getIo()->confirm(
+                $this->trans('commands.generate.command.questions.generator'),
+                false
+            );
+            $input->setOption('generator', $generator);
+        }
     }
 }