- $exact = in_array($name, $commands, true);
- if (count($commands) > 1 && !$exact) {
- $suggestions = $this->getAbbreviationSuggestions(array_values($commands));
+ $exact = \in_array($name, $commands, true) || isset($aliases[$name]);
+ if (\count($commands) > 1 && !$exact) {
+ $usableWidth = $this->terminal->getWidth() - 10;
+ $abbrevs = array_values($commands);
+ $maxLen = 0;
+ foreach ($abbrevs as $abbrev) {
+ $maxLen = max(Helper::strlen($abbrev), $maxLen);
+ }
+ $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) {
+ if (!$commandList[$cmd] instanceof Command) {
+ return $cmd;
+ }
+ $abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription();
+
+ return Helper::strlen($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
+ }, array_values($commands));
+ $suggestions = $this->getAbbreviationSuggestions($abbrevs);