8000 [Console] Show aliases in command description instead of in different… · symfony/symfony@548ab0a · GitHub
[go: up one dir, main page]

Skip to content

Commit 548ab0a

Browse files
juanmirodfabpot
authored andcommitted
[Console] Show aliases in command description instead of in different lines in application description
1 parent ea9d6e7 commit 548ab0a

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,22 @@ protected function describeApplication(Application $application, array $options
198198
}
199199

200200
// add commands by namespace
201+
$commands = $description->getCommands();
202+
201203
foreach ($description->getNamespaces() as $namespace) {
202204
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
203205
$this->writeText("\n");
204206
$this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
205207
}
206208

207209
foreach ($namespace['commands'] as $name) {
208-
$this->writeText("\n");
209-
$spacingWidth = $width - strlen($name);
210-
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
210+
if (isset($commands[$name])) {
211+
$this->writeText("\n");
212+
$spacingWidth = $width - strlen($name);
213+
$command = $commands[$name];
214+
$commandAliases = $this->getCommandAliasesText($command);
215+
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options);
216+
}
211217
}
212218
}
213219

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

235+
/**
236+
* Formats command aliases to show them in the command description.
237+
*
238+
* @param Command $command
239+
*
240+
* @return string
241+
*/
242+
private function getCommandAliasesText($command)
243+
{
244+
$text = '';
245+
$aliases = $command->getAliases();
246+
247+
if ($aliases) {
248+
$text = '['.implode('|', $aliases).'] ';
249+
}
250+
251+
return $text;
252+
}
253+
229254
/**
230255
* Formats input option/argument default value.
231256
*

src/Symfony/Component/Console/Tests/Fixtures/application_2.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
1414

1515
<comment>Available commands:</comment>
16-
<info>alias1</info> command 1 description
17-
<info>alias2</info> command 1 description
1816
<info>help</info> Displays help for a command
1917
<info>list</info> Lists commands
2018
<comment>descriptor</comment>
21-
<info>descriptor:command1</info> command 1 description
19+
<info>descriptor:command1</info> [alias1|alias2] command 1 description
2220
<info>descriptor:command2</info> command 2 description

0 commit comments

Comments
 (0)
0