Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Descriptor / TextDescriptor.php
index d02d07760516ee6aa561ae72c0209bc2b037a070..8018d9eff822ae3b9888bdc6fbe6bd73e3c27478 100644 (file)
@@ -98,10 +98,16 @@ class TextDescriptor extends Descriptor
      */
     protected function describeInputDefinition(InputDefinition $definition, array $options = [])
     {
+        $command_name = null;
+        if (array_key_exists('command', $options)) {
+            $command_name = $options['command']->getName();
+        }
+
         $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
         foreach ($definition->getArguments() as $argument) {
             $totalWidth = max($totalWidth, strlen($argument->getName()));
         }
+
         if ($definition->getArguments()) {
             $this->writeText($options['translator']->trans('commands.list.messages.arguments'), $options);
             $this->writeText("\n");
@@ -116,7 +122,17 @@ class TextDescriptor extends Descriptor
         if ($definition->getOptions()) {
             $laterOptions = [];
             $this->writeText($options['translator']->trans('commands.list.messages.options'), $options);
+
+            $exitOptionName = 'help';
+            if ($command_name === $exitOptionName) {
+                $exitOptionName = '';
+            }
+
             foreach ($definition->getOptions() as $option) {
+                if ($option->getName() === $exitOptionName) {
+                    break;
+                }
+
                 if (strlen($option->getShortcut()) > 1) {
                     $laterOptions[] = $option;
                     continue;
@@ -153,30 +169,42 @@ class TextDescriptor extends Descriptor
         $command->getSynopsis(true);
         $command->getSynopsis(false);
         $command->mergeApplicationDefinition(false);
+
         $this->writeText($command->trans('commands.list.messages.usage'), $options);
-        foreach (array_merge([$command->getSynopsis(true)], $command->getAliases(), $command->getUsages()) as $usage) {
+        foreach (array_merge([$command->getSynopsis(true)], $command->getAliases(), $command->getUsages()) as $key => $usage) {
+            if ($key > 0) {
+                $this->writeText("\n");
+            }
             $this->writeText('  '.$usage, $options);
+        }
+
+        $this->writeText("\n");
+        $definition = $command->getNativeDefinition();
+        if ($definition->getOptions() || $definition->getArguments()) {
+            $this->writeText("\n");
+            $options =
+                array_merge(
+                    $options,
+                    [ 'command' => $command ]
+                );
+            $this->describeInputDefinition($definition, $options);
             $this->writeText("\n");
         }
+
         if ($examples) {
             $this->writeText("\n");
             $this->writeText("<comment>Examples:</comment>", $options);
-            foreach ($examples as $example) {
+            foreach ($examples as $key => $example) {
                 $this->writeText("\n");
-                $this->writeText('  '.$example['description']);
+                if ($key != 0) {
+                    $this->writeText("\n");
+                }
+                $this->writeText('  <info>'.$example['description'].'</info>');
                 $this->writeText("\n");
                 $this->writeText('  '.$example['execution']);
-                $this->writeText("\n");
             }
         }
 
-        $this->writeText("\n");
-        $definition = $command->getNativeDefinition();
-        if ($definition->getOptions() || $definition->getArguments()) {
-            $this->writeText("\n");
-            $this->describeInputDefinition($definition, $options);
-            $this->writeText("\n");
-        }
         if ($help = $command->getProcessedHelp()) {
             $this->writeText("\n");
             $this->writeText($command->trans('commands.list.messages.help'), $options);
@@ -202,12 +230,29 @@ class TextDescriptor extends Descriptor
             if ('' != $help = $application->getHelp()) {
                 $this->writeText("$help\n\n", $options);
             }
-            $this->writeText($application->trans('commands.list.messages.usage'), $options);
-            $this->writeText($application->trans('commands.list.messages.usage_details'), $options);
-            $options['application'] = $application;
-            $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options);
-            $this->writeText("\n");
-            $this->writeText("\n");
+            if (empty($describedNamespace)) {
+                $this->writeText(
+                    $application->trans('commands.list.messages.usage'),
+                    $options
+                );
+                $this->writeText(
+                    $application->trans(
+                        'commands.list.messages.usage-details'
+                    ),
+                    $options
+                );
+                $options['application'] = $application;
+
+                $this->describeInputDefinition(
+                    new InputDefinition(
+                        $application->getDefinition()->getOptions()
+                    ),
+                    $options
+                );
+                $this->writeText("\n");
+                $this->writeText("\n");
+            }
+
             $width = $this->getColumnWidth($description->getCommands()) + 4;
             if ($describedNamespace) {
                 $this->writeText(sprintf($application->trans('commands.list.messages.comment'), $describedNamespace), $options);
@@ -219,6 +264,7 @@ class TextDescriptor extends Descriptor
                 'about',
                 'chain',
                 'check',
+                'composerize',
                 'exec',
                 'help',
                 'init',
@@ -248,14 +294,20 @@ class TextDescriptor extends Descriptor
                             implode(',', $description->getCommand($name)->getAliases())
                         );
                     }
+
                     $spacingWidth = $width - strlen($name.$alias);
+                    if ($spacingWidth < 0) {
+                        $spacingWidth = 0;
+                    }
+
                     $this->writeText(
                         sprintf(
                             '  <info>%s</info> <comment>%s</comment> %s%s',
                             $name,
                             $alias,
                             str_repeat(' ', $spacingWidth),
-                            $description->getCommand($name)->getDescription()
+                            $description->getCommand($name)->getDescription(
+                            )
                         ),
                         $options
                     );