[Console] Fixed command name guessing if an alternative is an alias.

This commit is contained in:
Jakub Zalas 2014-01-06 22:31:09 +00:00
parent 73edae9a79
commit ade448cf10
2 changed files with 23 additions and 0 deletions

View File

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

View File

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