Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/console/Descriptor/TextDescriptor.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/symfony/console/Descriptor/TextDescriptor.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/console/Descriptor/TextDescriptor.php Mon Apr 23 09:46:53 2018 +0100 @@ -143,7 +143,7 @@ $this->writeText('<comment>Usage:</comment>', $options); foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) { $this->writeText("\n"); - $this->writeText(' '.$usage, $options); + $this->writeText(' '.OutputFormatter::escape($usage), $options); } $this->writeText("\n"); @@ -191,7 +191,20 @@ $this->writeText("\n"); $this->writeText("\n"); - $width = $this->getColumnWidth($description->getCommands()); + $commands = $description->getCommands(); + $namespaces = $description->getNamespaces(); + if ($describedNamespace && $namespaces) { + // make sure all alias commands are included when describing a specific namespace + $describedNamespaceInfo = reset($namespaces); + foreach ($describedNamespaceInfo['commands'] as $name) { + $commands[$name] = $description->getCommand($name); + } + } + + // calculate max. width based on available commands per namespace + $width = $this->getColumnWidth(call_user_func_array('array_merge', array_map(function ($namespace) use ($commands) { + return array_intersect($namespace['commands'], array_keys($commands)); + }, $namespaces))); if ($describedNamespace) { $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options); @@ -199,23 +212,26 @@ $this->writeText('<comment>Available commands:</comment>', $options); } - // add commands by namespace - $commands = $description->getCommands(); + foreach ($namespaces as $namespace) { + $namespace['commands'] = array_filter($namespace['commands'], function ($name) use ($commands) { + return isset($commands[$name]); + }); - foreach ($description->getNamespaces() as $namespace) { + if (!$namespace['commands']) { + continue; + } + if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); $this->writeText(' <comment>'.$namespace['id'].'</comment>', $options); } foreach ($namespace['commands'] as $name) { - 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); - } + $this->writeText("\n"); + $spacingWidth = $width - Helper::strlen($name); + $command = $commands[$name]; + $commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : ''; + $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options); } } @@ -237,11 +253,9 @@ /** * Formats command aliases to show them in the command description. * - * @param Command $command - * * @return string */ - private function getCommandAliasesText($command) + private function getCommandAliasesText(Command $command) { $text = ''; $aliases = $command->getAliases(); @@ -280,7 +294,7 @@ } /** - * @param Command[] $commands + * @param (Command|string)[] $commands * * @return int */ @@ -289,13 +303,17 @@ $widths = array(); foreach ($commands as $command) { - $widths[] = Helper::strlen($command->getName()); - foreach ($command->getAliases() as $alias) { - $widths[] = Helper::strlen($alias); + if ($command instanceof Command) { + $widths[] = Helper::strlen($command->getName()); + foreach ($command->getAliases() as $alias) { + $widths[] = Helper::strlen($alias); + } + } else { + $widths[] = Helper::strlen($command); } } - return max($widths) + 2; + return $widths ? max($widths) + 2 : 0; } /** @@ -303,7 +321,7 @@ * * @return int */ - private function calculateTotalWidthForOptions($options) + private function calculateTotalWidthForOptions(array $options) { $totalWidth = 0; foreach ($options as $option) {