Skip to content

Commit

Permalink
[Console] Inline exact-match handling with 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Feb 15, 2020
1 parent b92168c commit e13470c
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 e13470c

Please sign in to comment.