Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,22 @@ protected function describeApplication(Application $application, array $options
}

// add commands by namespace
$commands = $description->getCommands();

foreach ($description->getNamespaces() as $namespace) {
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
$this->writeText("\n");
$this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
}

foreach ($namespace['commands'] as $name) {
$this->writeText("\n");
$spacingWidth = $width - 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 - 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);
}
}
}

Expand All @@ -226,6 +232,25 @@ private function writeText($content, array $options = array())
);
}

/**
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

<comment>Available commands:</comment>
<info>alias1</info> command 1 description
<info>alias2</info> command 1 description
<info>help</info> Displays help for a command
<info>list</info> Lists commands
<comment>descriptor</comment>
<info>descriptor:command1</info> command 1 description
<info>descriptor:command1</info> [alias1|alias2] command 1 description
<info>descriptor:command2</info> command 2 description