Skip to content

Commit

Permalink
[Console] Fixed command name guessing if an alternative is an alias.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Jan 6, 2014
1 parent 73edae9 commit ade448c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -562,6 +562,16 @@ public function find($name)
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));
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -393,6 +393,19 @@ public function testFindAlternativeCommands()
}
}

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();
Expand Down

0 comments on commit ade448c

Please sign in to comment.