8000 bug #35094 [Console] Fix filtering out identical alternatives when th… · symfony/symfony@1908434 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1908434

Browse files
committed
bug #35094 [Console] Fix filtering out identical alternatives when there is a command loader (fancyweb)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Fix filtering out identical alternatives when there is a command loader | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #35089 | License | MIT | Doc PR | - CommandLoader commands needs to be loaded to resolve their names and filter them. Commits ------- 589e93e [Console] Fix filtering out identical alternatives when there is a command loader
2 parents 135c6f7 + 589e93e commit 1908434

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Symfony/Component/Console/Application.php

Lines 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

Lines 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