Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / drupal / console-core / src / Descriptor / TextDescriptor.php
index 002b1473efe3f65eb11496a92a4a66f27889397f..54f9808200f7a1425c4e07e5eed313e84639be88 100644 (file)
@@ -29,7 +29,7 @@ class TextDescriptor extends Descriptor
     /**
      * {@inheritdoc}
      */
-    protected function describeInputArgument(InputArgument $argument, array $options = array())
+    protected function describeInputArgument(InputArgument $argument, array $options = [])
     {
         if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
             $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($argument->getDefault()));
@@ -56,7 +56,7 @@ class TextDescriptor extends Descriptor
     /**
      * {@inheritdoc}
      */
-    protected function describeInputOption(InputOption $option, array $options = array())
+    protected function describeInputOption(InputOption $option, array $options = [])
     {
         if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
             $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($option->getDefault()));
@@ -70,7 +70,7 @@ class TextDescriptor extends Descriptor
                 $value = '['.$value.']';
             }
         }
-        $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option));
+        $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions([$option]);
         $synopsis = sprintf(
             '%s%s',
             $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : '    ',
@@ -96,17 +96,23 @@ class TextDescriptor extends Descriptor
     /**
      * {@inheritdoc}
      */
-    protected function describeInputDefinition(InputDefinition $definition, array $options = array())
+    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");
             foreach ($definition->getArguments() as $argument) {
-                $this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth)));
+                $this->describeInputArgument($argument, array_merge($options, ['total_width' => $totalWidth]));
                 $this->writeText("\n");
             }
         }
@@ -114,42 +120,93 @@ class TextDescriptor extends Descriptor
             $this->writeText("\n");
         }
         if ($definition->getOptions()) {
-            $laterOptions = array();
+            $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;
                 }
                 $this->writeText("\n");
-                $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
+                $this->describeInputOption($option, array_merge($options, ['total_width' => $totalWidth]));
             }
             foreach ($laterOptions as $option) {
                 $this->writeText("\n");
-                $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
+                $this->describeInputOption($option, array_merge($options, ['total_width' => $totalWidth]));
             }
         }
     }
     /**
      * {@inheritdoc}
      */
-    protected function describeCommand(Command $command, array $options = array())
+    protected function describeCommand(Command $command, array $options = [])
     {
+        $namespace = substr(
+            $command->getName(),
+            0,
+            (strpos($command->getName(), ':')?:0)
+        );
+        $commandData = $command->getApplication()->getData();
+        $examples = [];
+        if (array_key_exists($namespace, $commandData['commands'])) {
+            $commands = $commandData['commands'][$namespace];
+            foreach ($commands as $item) {
+                if ($item['name'] == $command->getName()) {
+                    $examples = $item['examples'];
+                    break;
+                }
+            }
+        }
+
         $command->getSynopsis(true);
         $command->getSynopsis(false);
         $command->mergeApplicationDefinition(false);
+
         $this->writeText($command->trans('commands.list.messages.usage'), $options);
-        foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) {
-            $this->writeText("\n");
+        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 $key => $example) {
+                $this->writeText("\n");
+                if ($key != 0) {
+                    $this->writeText("\n");
+                }
+                $this->writeText('  <info>'.$example['description'].'</info>');
+                $this->writeText("\n");
+                $this->writeText('  '.$example['execution']);
+            }
+        }
+
         if ($help = $command->getProcessedHelp()) {
             $this->writeText("\n");
             $this->writeText($command->trans('commands.list.messages.help'), $options);
@@ -161,7 +218,7 @@ class TextDescriptor extends Descriptor
     /**
      * {@inheritdoc}
      */
-    protected function describeApplication(Application $application, array $options = array())
+    protected function describeApplication(Application $application, array $options = [])
     {
         $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
         $description = new ApplicationDescription($application, $describedNamespace);
@@ -175,17 +232,33 @@ 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);
-            }
-            else {
+            } else {
                 $this->writeText($application->trans('commands.list.messages.available-commands'), $options);
             }
 
@@ -193,6 +266,7 @@ class TextDescriptor extends Descriptor
                 'about',
                 'chain',
                 'check',
+                'composerize',
                 'exec',
                 'help',
                 'init',
@@ -208,8 +282,7 @@ class TextDescriptor extends Descriptor
                     $this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
                 }
                 foreach ($namespace['commands'] as $name) {
-
-                    if (ApplicationDescription::GLOBAL_NAMESPACE == $namespace['id']){
+                    if (ApplicationDescription::GLOBAL_NAMESPACE == $namespace['id']) {
                         if (!in_array($name, $singleCommands)) {
                             continue;
                         }
@@ -217,19 +290,26 @@ class TextDescriptor extends Descriptor
 
                     $this->writeText("\n");
                     $alias = '';
-                    if ($description->getCommand($name)->getAliases()){
+                    if ($description->getCommand($name)->getAliases()) {
                         $alias = sprintf(
                             '(%s)',
                             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',
+                        sprintf(
+                            '  <info>%s</info> <comment>%s</comment> %s%s',
                             $name,
                             $alias,
                             str_repeat(' ', $spacingWidth),
-                            $description->getCommand($name)->getDescription()
+                            $description->getCommand($name)->getDescription(
+                            )
                         ),
                         $options
                     );
@@ -241,7 +321,7 @@ class TextDescriptor extends Descriptor
     /**
      * {@inheritdoc}
      */
-    private function writeText($content, array $options = array())
+    private function writeText($content, array $options = [])
     {
         $this->write(
             isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,