|
30 | 30 | use Symfony\Component\Console\Command\HelpCommand;
|
31 | 31 | use Symfony\Component\Console\Command\ListCommand;
|
32 | 32 | use Symfony\Component\Console\Helper\HelperSet;
|
| 33 | +use Symfony\Component\Console\Helper\Helper; |
33 | 34 | use Symfony\Component\Console\Helper\FormatterHelper;
|
34 | 35 | use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
35 | 36 | use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
@@ -503,7 +504,7 @@ public function findNamespace($namespace)
|
503 | 504 |
|
504 | 505 | $exact = in_array($namespace, $namespaces, true);
|
505 | 506 | if (count($namespaces) > 1 && !$exact) {
|
506 |
| - throw new CommandNotFoundException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces)); |
| 507 | + throw new CommandNotFoundException(sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces)); |
507 | 508 | }
|
508 | 509 |
|
509 | 510 | return $exact ? $namespace : reset($namespaces);
|
@@ -559,9 +560,20 @@ public function find($name)
|
559 | 560 |
|
560 | 561 | $exact = in_array($name, $commands, true);
|
561 | 562 | if (count($commands) > 1 && !$exact) {
|
562 |
| - $suggestions = $this->getAbbreviationSuggestions(array_values($commands)); |
| 563 | + $usableWidth = $this->terminal->getWidth() - 10; |
| 564 | + $abbrevs = array_values($commands); |
| 565 | + $maxLen = 0; |
| 566 | + foreach ($abbrevs as $abbrev) { |
| 567 | + $maxLen = max(Helper::strlen($abbrev), $maxLen); |
| 568 | + } |
| 569 | + $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) { |
| 570 | + $abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription(); |
| 571 | + |
| 572 | + return Helper::strlen($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev; |
| 573 | + }, array_values($commands)); |
| 574 | + $suggestions = $this->getAbbreviationSuggestions($abbrevs); |
563 | 575 |
|
564 |
| - throw new CommandNotFoundException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions), array_values($commands)); |
| 576 | + throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands)); |
565 | 577 | }
|
566 | 578 |
|
567 | 579 | return $this->get($exact ? $name : reset($commands));
|
@@ -944,7 +956,7 @@ protected function getDefaultHelperSet()
|
944 | 956 | */
|
945 | 957 | private function getAbbreviationSuggestions($abbrevs)
|
946 | 958 | {
|
947 |
| - return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : ''); |
| 959 | + return ' '.implode("\n ", $abbrevs); |
948 | 960 | }
|
949 | 961 |
|
950 | 962 | /**
|
|
0 commit comments