Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 589e93e

Browse filesBrowse files
committed
[Console] Fix filtering out identical alternatives when there is a command loader
1 parent 135c6f7 commit 589e93e
Copy full SHA for 589e93e

File tree

2 files changed

+10
-6
lines changed
Filter options

2 files changed

+10
-6
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,13 @@ public function find($name)
645645
// filter out aliases for commands which are already on the list
646646
if (\count($commands) > 1) {
647647
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
648-
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands, &$aliases) {
649-
$commandName = $commandList[$nameOrAlias] instanceof Command ? $commandList[$nameOrAlias]->getName() : $nameOrAlias;
648+
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
649+
if (!$commandList[$nameOrAlias] instanceof Command) {
650+
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
651+
}
652+
653+
$commandName = $commandList[$nameOrAlias]->getName();
654+
650655
$aliases[$nameOrAlias] = $commandName;
651656

652657
return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
@@ -662,10 +667,6 @@ public function find($name)
662667
$maxLen = max(Helper::strlen($abbrev), $maxLen);
663668
}
664669
$abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) {
665-
if (!$commandList[$cmd] instanceof Command) {
666-
$commandList[$cmd] = $this->commandLoader->get($cmd);
667-
}
668-
669670
if ($commandList[$cmd]->isHidden()) {
670671
return false;
671672
}

‎src/Symfony/Component/Console/Tests/ApplicationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ public function testFindAlternativeCommandsWithAnAlias()
568568
$fooCommand->setAliases(['foo2']);
569569

570570
$application = new Application();
571+
$application->setCommandLoader(new FactoryCommandLoader([
572+
'foo3' => static function () use ($fooCommand) { return $fooCommand; },
573+
]));
571574
$application->add($fooCommand);
572575

573576
$result = $application->find('foo');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.