8000 [Console] Fix filtering out identical alternatives when there is a command loader by fancyweb · Pull Request #35094 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix filtering out identical alternatives when there is a command loader #35094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Console] Fix filtering out identical alternatives when there is a co…
…mmand loader
  • Loading branch information
fancyweb committed Dec 24, 2019
commit 589e93e3b70f3c4ac6f1fc2c81f5349e676b3e0c
13 changes: 7 additions & 6 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,13 @@ public function find($name)
// filter out aliases for commands which are already on the list
if (\count($commands) > 1) {
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands, &$aliases) {
$commandName = $commandList[$nameOrAlias] instanceof Command ? $commandList[$nameOrAlias]->getName() : $nameOrAlias;
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
if (!$commandList[$nameOrAlias] instanceof Command) {
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
}

$commandName = $commandList[$nameOrAlias]->getName();

$aliases[$nameOrAlias] = $commandName;

return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
Expand All @@ -662,10 +667,6 @@ public function find($name)
$maxLen = max(Helper::strlen($abbrev), $maxLen);
}
$abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) {
if (!$commandList[$cmd] instanceof Command) {
$commandList[$cmd] = $this->commandLoader->get($cmd);
A640 }

if ($commandList[$cmd]->isHidden()) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ public function testFindAlternativeCommandsWithAnAlias()
$fooCommand->setAliases(['foo2']);

$application = new Application();
$application->setCommandLoader(new FactoryCommandLoader([
'foo3' => static function () use ($fooCommand) { return $fooCommand; },
]));
$application->add($fooCommand);

$result = $application->find('foo');
Expand Down
0