diff --git a/src/mantle/console/class-exception-handler.php b/src/mantle/console/class-exception-handler.php
index 8a224f473..e92fd7f14 100644
--- a/src/mantle/console/class-exception-handler.php
+++ b/src/mantle/console/class-exception-handler.php
@@ -11,6 +11,8 @@
use Mantle\Contracts\Exceptions\Handler as Exceptions_Handler;
use Throwable;
+use function Termwind\render;
+
/**
* Exception Handler for use in the console.
*
@@ -61,6 +63,14 @@ public function should_report( Throwable $e ) {
* @throws Throwable Thrown on error rendering.
*/
public function render( $request, Throwable $e ) {
+ if ( $e instanceof \Symfony\Component\Console\Exception\RuntimeException ) {
+ render(
+ '
' . $e->getMessage() . '
'
+ );
+
+ return;
+ }
+
( new \NunoMaduro\Collision\Provider() )->register();
throw $e;
diff --git a/src/mantle/framework/console/class-kernel.php b/src/mantle/framework/console/class-kernel.php
index c6f217903..292d3ac17 100644
--- a/src/mantle/framework/console/class-kernel.php
+++ b/src/mantle/framework/console/class-kernel.php
@@ -17,12 +17,15 @@
use Mantle\Contracts\Console\Application as Console_Application_Contract;
use Mantle\Contracts\Console\Kernel as Kernel_Contract;
use Mantle\Contracts\Exceptions\Handler as Exception_Handler;
+use Mantle\Support\Str;
use Mantle\Support\Traits\Loads_Classes;
use ReflectionClass;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Throwable;
+use function Mantle\Support\Helpers\collect;
+
/**
* Console Kernel
*/
@@ -321,7 +324,12 @@ protected function register_wpcli_command() {
Command::PREFIX,
function () {
$status = $this->handle(
- new \Symfony\Component\Console\Input\ArgvInput( array_slice( $_SERVER['argv'] ?? [], 1 ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ new \Symfony\Component\Console\Input\ArgvInput(
+ collect( (array) ( $_SERVER['argv'] ?? [] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+ // Remove the `wp` prefix from argv and any invalid arguments (such as --url).
+ ->filter( fn ( $value, $index ) => 0 !== $index && ! Str::starts_with( $value, '--url=' ) )
+ ->all()
+ ),
new \Symfony\Component\Console\Output\ConsoleOutput(),
);
diff --git a/src/mantle/framework/exceptions/class-handler.php b/src/mantle/framework/exceptions/class-handler.php
index 3e0ae2815..96caa4083 100644
--- a/src/mantle/framework/exceptions/class-handler.php
+++ b/src/mantle/framework/exceptions/class-handler.php
@@ -59,6 +59,7 @@ abstract class Handler implements Contract {
HttpException::class,
Model_Not_Found_Exception::class,
ResourceNotFoundException::class,
+ \Symfony\Component\Console\Exception\RuntimeException::class,
];
/**