Skip to content

Commit 9b5017c

Browse files
committed
bug symfony#9957 [Console] Fixed command name guessing if an alternative is an alias (jakzal)
This PR was merged into the 2.4 branch. Discussion ---------- [Console] Fixed command name guessing if an alternative is an alias | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#9953 | License | MIT | Doc PR | - Commits ------- ade448c [Console] Fixed command name guessing if an alternative is an alias.
2 parents 73edae9 + ade448c commit 9b5017c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,16 @@ public function find($name)
562562
throw new \InvalidArgumentException($message);
563563
}
564564

565+
// filter out aliases for commands which are already on the list
566+
if (count($commands) > 1) {
567+
$commandList = $this->commands;
568+
$commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
569+
$commandName = $commandList[$nameOrAlias]->getName();
570+
571+
return $commandName === $nameOrAlias || !in_array($commandName, $commands);
572+
});
573+
}
574+
565575
$exact = in_array($name, $commands, true);
566576
if (count($commands) > 1 && !$exact) {
567577
$suggestions = $this->getAbbreviationSuggestions(array_values($commands));

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,19 @@ public function testFindAlternativeCommands()
393393
}
394394
}
395395

396+
public function testFindAlternativeCommandsWithAnAlias()
397+
{
398+
$fooCommand = new \FooCommand();
399+
$fooCommand->setAliases(array('foo2'));
400+
401+
$application = new Application();
402+
$application->add($fooCommand);
403+
404+
$result = $application->find('foo');
405+
406+
$this->assertSame($fooCommand, $result);
407+
}
408+
396409
public function testFindAlternativeNamespace()
397410
{
398411
$application = new Application();

0 commit comments

Comments
 (0)