Skip to content

Commit 5accd36

Browse files
SimperfitRobin Chalas
authored andcommitted
[Console] Optimisation on getting the command
1 parent 3105255 commit 5accd36

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Application.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ public function find($name)
623623
}
624624
}
625625

626+
if ($this->has($name)) {
627+
return $this->get($name);
628+
}
629+
626630
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
627631
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
628632
$commands = preg_grep('{^'.$expr.'}', $allCommands);
@@ -663,8 +667,7 @@ public function find($name)
663667
}));
664668
}
665669

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

687-
return $this->get($exact ? $name : reset($commands));
690+
return $this->get(reset($commands));
688691
}
689692

690693
/**

0 commit comments

Comments
 (0)