Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console-core / src / Descriptor / TextDescriptor.php
index 002b1473efe3f65eb11496a92a4a66f27889397f..d02d07760516ee6aa561ae72c0209bc2b037a070 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,7 +96,7 @@ class TextDescriptor extends Descriptor
     /**
      * {@inheritdoc}
      */
-    protected function describeInputDefinition(InputDefinition $definition, array $options = array())
+    protected function describeInputDefinition(InputDefinition $definition, array $options = [])
     {
         $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
         foreach ($definition->getArguments() as $argument) {
@@ -106,7 +106,7 @@ class TextDescriptor extends Descriptor
             $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,7 +114,7 @@ class TextDescriptor extends Descriptor
             $this->writeText("\n");
         }
         if ($definition->getOptions()) {
-            $laterOptions = array();
+            $laterOptions = [];
             $this->writeText($options['translator']->trans('commands.list.messages.options'), $options);
             foreach ($definition->getOptions() as $option) {
                 if (strlen($option->getShortcut()) > 1) {
@@ -122,27 +122,54 @@ class TextDescriptor extends Descriptor
                     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();
+        $commands = $commandData['commands'][$namespace];
+        $examples = [];
+        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 $usage) {
             $this->writeText('  '.$usage, $options);
+            $this->writeText("\n");
         }
+        if ($examples) {
+            $this->writeText("\n");
+            $this->writeText("<comment>Examples:</comment>", $options);
+            foreach ($examples as $example) {
+                $this->writeText("\n");
+                $this->writeText('  '.$example['description']);
+                $this->writeText("\n");
+                $this->writeText('  '.$example['execution']);
+                $this->writeText("\n");
+            }
+        }
+
         $this->writeText("\n");
         $definition = $command->getNativeDefinition();
         if ($definition->getOptions() || $definition->getArguments()) {
@@ -161,7 +188,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);
@@ -184,8 +211,7 @@ class TextDescriptor extends Descriptor
             $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);
             }
 
@@ -208,8 +234,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,7 +242,7 @@ 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())
@@ -225,7 +250,8 @@ class TextDescriptor extends Descriptor
                     }
                     $spacingWidth = $width - strlen($name.$alias);
                     $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),
@@ -241,7 +267,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,