Skip to content

Commit 8419a76

Browse files
committed
[Console] Fixed command name guessing if an alternative is an alias.
1 parent 4c1ed2f commit 8419a76

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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));

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)