Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / console / Descriptor / TextDescriptor.php
index c0dd4830c3d2dd17361147ad50a8f184552e87ed..c306d59c07a2efbddb5c9d5acd18abbf3c645e81 100644 (file)
@@ -200,6 +200,8 @@ class TextDescriptor extends Descriptor
             }
 
             // add commands by namespace
+            $commands = $description->getCommands();
+
             foreach ($description->getNamespaces() as $namespace) {
                 if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                     $this->writeText("\n");
@@ -207,9 +209,13 @@ class TextDescriptor extends Descriptor
                 }
 
                 foreach ($namespace['commands'] as $name) {
-                    $this->writeText("\n");
-                    $spacingWidth = $width - Helper::strlen($name);
-                    $this->writeText(sprintf('  <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
+                    if (isset($commands[$name])) {
+                        $this->writeText("\n");
+                        $spacingWidth = $width - Helper::strlen($name);
+                        $command = $commands[$name];
+                        $commandAliases = $this->getCommandAliasesText($command);
+                        $this->writeText(sprintf('  <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options);
+                    }
                 }
             }
 
@@ -228,6 +234,25 @@ class TextDescriptor extends Descriptor
         );
     }
 
+    /**
+     * Formats command aliases to show them in the command description.
+     *
+     * @param Command $command
+     *
+     * @return string
+     */
+    private function getCommandAliasesText($command)
+    {
+        $text = '';
+        $aliases = $command->getAliases();
+
+        if ($aliases) {
+            $text = '['.implode('|', $aliases).'] ';
+        }
+
+        return $text;
+    }
+
     /**
      * Formats input option/argument default value.
      *
@@ -237,6 +262,10 @@ class TextDescriptor extends Descriptor
      */
     private function formatDefaultValue($default)
     {
+        if (INF === $default) {
+            return 'INF';
+        }
+
         if (is_string($default)) {
             $default = OutputFormatter::escape($default);
         } elseif (is_array($default)) {
@@ -247,10 +276,6 @@ class TextDescriptor extends Descriptor
             }
         }
 
-        if (\PHP_VERSION_ID < 50400) {
-            return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default));
-        }
-
         return str_replace('\\\\', '\\', json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
     }
 
@@ -283,7 +308,7 @@ class TextDescriptor extends Descriptor
         $totalWidth = 0;
         foreach ($options as $option) {
             // "-" + shortcut + ", --" + name
-            $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName());
+            $nameLength = 1 + max(Helper::strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName());
 
             if ($option->acceptValue()) {
                 $valueLength = 1 + Helper::strlen($option->getName()); // = + value