8000 feature #18790 [Console] Show aliases in command description instead … · symfony/symfony@4256b68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4256b68

Browse files
committed
feature #18790 [Console] Show aliases in command description instead of in different lines in application description (juanmirod)
This PR was squashed before being merged into the 3.2-dev branch (closes #18790). Discussion ---------- [Console] Show aliases in command description instead of in different lines in application description | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18351 | License | MIT | Doc PR | This PR is a suggestion about the bug referenced in ticket 18351. The problem is that aliases create new lines with identical descriptions in the application description, it is suggested to show the aliases in the command description. I had to modify one application fixture to meet this new behaviour and make the tests pass, but I don't think that a new application fixture is needed to test this having the application fixture 2. Comments are welcome, this is my first PR in Symfony so if I need to meet any more requirements to make it correct to merge just tell me please. Commits ------- 548ab0a [Console] Show aliases in command description instead of in different lines in application description
2 parents 27f4680 + 548ab0a commit 4256b68

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