Skip to content
Permalink
Browse files

[Console] Optimisation on getting the command

  • Loading branch information...
Simperfit authored and chalasr committed May 8, 2019
1 parent e19db43 commit 3d6b30330e85e07194a0663d1997052dfe2b6a84
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/Symfony/Component/Console/Application.php
@@ -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);
@@ -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;
@@ -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));
}
/**

0 comments on commit 3d6b303

Please sign in to comment.
You can’t perform that action at this time.