Skip to content

Commit 6af9416

Browse files
authored
Merge pull request #2164 from MGatner/cli-returns
Exit error code on CLI Command failure
2 parents 30e6994 + 279e71e commit 6af9416

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

spark

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ ini_set('display_errors', 1);
5353
// Show basic information before we do anything else.
5454
$console->showHeader();
5555

56-
// fire off the command the main framework.
57-
$console->run();
56+
// fire off the command in the main framework.
57+
$response = $console->run();
58+
if ($response->getStatusCode() >= 300)
59+
{
60+
exit($response->getStatusCode());
61+
}

system/CLI/CommandRunner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CommandRunner extends Controller
7171
* @param string $method
7272
* @param array ...$params
7373
*
74+
* @return mixed
7475
* @throws \ReflectionException
7576
*/
7677
public function _remap($method, ...$params)
@@ -81,7 +82,7 @@ public function _remap($method, ...$params)
8182
array_shift($params);
8283
}
8384

84-
$this->index($params);
85+
return $this->index($params);
8586
}
8687

8788
//--------------------------------------------------------------------

system/CodeIgniter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
355355
else
356356
{
357357
$response = $this->response;
358+
359+
// Set response code for CLI command failures
360+
if (is_numeric($returned) || $returned === false)
361+
{
362+
$response->setStatusCode(400);
363+
}
358364
}
359365

360366
if ($response instanceof Response)

0 commit comments

Comments
 (0)