diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index 560ce150e2..1480266ed6 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -198,6 +198,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"); @@ -205,9 +207,13 @@ class TextDescriptor extends Descriptor } foreach ($namespace['commands'] as $name) { - $this->writeText("\n"); - $spacingWidth = $width - strlen($name); - $this->writeText(sprintf(' %s%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); + if (isset($commands[$name])) { + $this->writeText("\n"); + $spacingWidth = $width - strlen($name); + $command = $commands[$name]; + $commandAliases = $this->getCommandAliasesText($command); + $this->writeText(sprintf(' %s%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options); + } } } @@ -226,6 +232,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. * diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt index 292aa829d8..268a0c0646 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt @@ -13,10 +13,8 @@ -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: - alias1 command 1 description - alias2 command 1 description help Displays help for a command list Lists commands descriptor - descriptor:command1 command 1 description + descriptor:command1 [alias1|alias2] command 1 description descriptor:command2 command 2 description