Skip to content

Commit 38fd6a7

Browse files
authored
[9.x] Improves command not found (#1242)
* Improves console output of not found command * Uses Laravel v9.21
1 parent e34fc42 commit 38fd6a7

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

composer.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616
],
1717
"require": {
1818
"php": "^8.0.2",
19-
"illuminate/auth": "^9.0",
20-
"illuminate/broadcasting": "^9.0",
21-
"illuminate/bus": "^9.0",
22-
"illuminate/cache": "^9.0",
23-
"illuminate/collections": "^9.0",
24-
"illuminate/config": "^9.0",
25-
"illuminate/console": "^9.0",
26-
"illuminate/container": "^9.0",
27-
"illuminate/contracts": "^9.0",
28-
"illuminate/database": "^9.0",
29-
"illuminate/encryption": "^9.0",
30-
"illuminate/events": "^9.0",
31-
"illuminate/filesystem": "^9.0",
32-
"illuminate/hashing": "^9.0",
33-
"illuminate/http": "^9.0",
34-
"illuminate/macroable": "^9.0",
35-
"illuminate/pagination": "^9.0",
36-
"illuminate/pipeline": "^9.0",
37-
"illuminate/queue": "^9.0",
38-
"illuminate/support": "^9.0",
39-
"illuminate/testing": "^9.0",
40-
"illuminate/translation": "^9.0",
41-
"illuminate/validation": "^9.0",
42-
"illuminate/view": "^9.0",
43-
"illuminate/log": "^9.0",
19+
"illuminate/auth": "^9.21",
20+
"illuminate/broadcasting": "^9.21",
21+
"illuminate/bus": "^9.21",
22+
"illuminate/cache": "^9.21",
23+
"illuminate/collections": "^9.21",
24+
"illuminate/config": "^9.21",
25+
"illuminate/console": "^9.21",
26+
"illuminate/container": "^9.21",
27+
"illuminate/contracts": "^9.21",
28+
"illuminate/database": "^9.21",
29+
"illuminate/encryption": "^9.21",
30+
"illuminate/events": "^9.21",
31+
"illuminate/filesystem": "^9.21",
32+
"illuminate/hashing": "^9.21",
33+
"illuminate/http": "^9.21",
34+
"illuminate/macroable": "^9.21",
35+
"illuminate/pagination": "^9.21",
36+
"illuminate/pipeline": "^9.21",
37+
"illuminate/queue": "^9.21",
38+
"illuminate/support": "^9.21",
39+
"illuminate/testing": "^9.21",
40+
"illuminate/translation": "^9.21",
41+
"illuminate/validation": "^9.21",
42+
"illuminate/view": "^9.21",
43+
"illuminate/log": "^9.21",
4444
"dragonmantank/cron-expression": "^3.1",
4545
"nikic/fast-route": "^1.3",
4646
"symfony/console": "^6.0",

src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function bootstrapRouter()
162162
*/
163163
public function version()
164164
{
165-
return 'Lumen (9.0.3) (Laravel Components ^9.0)';
165+
return 'Lumen (9.0.3) (Laravel Components ^9.21)';
166166
}
167167

168168
/**

src/Exceptions/Handler.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Exception;
66
use Illuminate\Auth\Access\AuthorizationException;
7+
use Illuminate\Console\View\Components\BulletList;
8+
use Illuminate\Console\View\Components\Error;
79
use Illuminate\Contracts\Debug\ExceptionHandler;
810
use Illuminate\Contracts\Support\Responsable;
911
use Illuminate\Database\Eloquent\ModelNotFoundException;
@@ -14,6 +16,7 @@
1416
use Illuminate\Validation\ValidationException;
1517
use Psr\Log\LoggerInterface;
1618
use Symfony\Component\Console\Application as ConsoleApplication;
19+
use Symfony\Component\Console\Exception\CommandNotFoundException;
1720
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
1821
use Symfony\Component\HttpKernel\Exception\HttpException;
1922
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
@@ -199,6 +202,23 @@ protected function renderExceptionWithSymfony(Throwable $e, $debug)
199202
*/
200203
public function renderForConsole($output, Throwable $e)
201204
{
205+
if ($e instanceof CommandNotFoundException) {
206+
$message = str($e->getMessage())->explode('.')->first();
207+
208+
if (! empty($alternatives = $e->getAlternatives())) {
209+
$message .= '. Did you mean one of these?';
210+
211+
with(new Error($output))->render($message);
212+
with(new BulletList($output))->render($e->getAlternatives());
213+
214+
$output->writeln('');
215+
} else {
216+
with(new Error($output))->render($message);
217+
}
218+
219+
return;
220+
}
221+
202222
(new ConsoleApplication)->renderThrowable($e, $output);
203223
}
204224

0 commit comments

Comments
 (0)