Skip to content

Commit

Permalink
minor #35734 [Console] Inline exact-match handling with 4.4 (chalasr)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Inline exact-match handling with 4.4

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #35696 (comment)
| License       | MIT
| Doc PR        | -

This reduces the patch for #35696 (not released yet), inlining 3.4's code with 4.4 which was not impacted by the fixed bug. The reverted logic was useless starting from 4.4.
Thanks @stof for the hint.

Commits
-------

e13470c [Console] Inline exact-match handling with 4.4
  • Loading branch information
chalasr committed Feb 15, 2020
2 parents b92168c + e13470c commit 334f020
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -608,6 +608,10 @@ public function find($name)
}
}

if ($this->has($name)) {
return $this->get($name);
}

$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
$commands = preg_grep('{^'.$expr.'}', $allCommands);
Expand Down Expand Up @@ -645,15 +649,7 @@ 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;

if (isset($commandList[$name])) {
return $this->get($name);
}

foreach ($commands as $k => $nameOrAlias) {
if ($nameOrAlias === $name) {
return $this->get($nameOrAlias);
}
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
if (!$commandList[$nameOrAlias] instanceof Command) {
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
}
Expand All @@ -662,14 +658,8 @@ public function find($name)

$aliases[$nameOrAlias] = $commandName;

if ($commandName === $nameOrAlias || !\in_array($commandName, $commands)) {
continue;
}

unset($commands[$k]);
}

$commands = array_unique($commands);
return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
}));
}

$exact = \in_array($name, $commands, true) || isset($aliases[$name]);
Expand Down

0 comments on commit 334f020

Please sign in to comment.