Skip to content

Commit

Permalink
[Console] Optimisation on getting the command
Browse files Browse the repository at this point in the history
  • Loading branch information
Simperfit authored and Robin Chalas committed May 14, 2019
1 parent e19db43 commit 3d6b303
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,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 @@ -663,8 +667,7 @@ public function find($name)
}));
}

$exact = \in_array($name, $commands, true) || isset($aliases[$name]);
if (\count($commands) > 1 && !$exact) {
if (\count($commands) > 1) {
$usableWidth = $this->terminal->getWidth() - 10;
$abbrevs = array_values($commands);
$maxLen = 0;
Expand All @@ -684,7 +687,7 @@ public function find($name)
throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands));
}

return $this->get($exact ? $name : reset($commands));
return $this->get(reset($commands));
}

/**
Expand Down

0 comments on commit 3d6b303

Please sign in to comment.