[Console] Fixed command name guessing if an alternative is an alias.
This commit is contained in:
parent
73edae9a79
commit
ade448cf10
@ -562,6 +562,16 @@ class Application
|
||||
throw new \InvalidArgumentException($message);
|
||||
}
|
||||
|
||||
// filter out aliases for commands which are already on the list
|
||||
if (count($commands) > 1) {
|
||||
$commandList = $this->commands;
|
||||
$commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
|
||||
$commandName = $commandList[$nameOrAlias]->getName();
|
||||
|
||||
return $commandName === $nameOrAlias || !in_array($commandName, $commands);
|
||||
});
|
||||
}
|
||||
|
||||
$exact = in_array($name, $commands, true);
|
||||
if (count($commands) > 1 && !$exact) {
|
||||
$suggestions = $this->getAbbreviationSuggestions(array_values($commands));
|
||||
|
@ -393,6 +393,19 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindAlternativeCommandsWithAnAlias()
|
||||
{
|
||||
$fooCommand = new \FooCommand();
|
||||
$fooCommand->setAliases(array('foo2'));
|
||||
|
||||
$application = new Application();
|
||||
$application->add($fooCommand);
|
||||
|
||||
$result = $application->find('foo');
|
||||
|
||||
$this->assertSame($fooCommand, $result);
|
||||
}
|
||||
|
||||
public function testFindAlternativeNamespace()
|
||||
{
|
||||
$application = new Application();
|
||||
|
Reference in New Issue
Block a user