Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit error code on CLI Command failure #2164

Merged
merged 3 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ ini_set('display_errors', 1);
// Show basic information before we do anything else.
$console->showHeader();

// fire off the command the main framework.
$console->run();
// fire off the command in the main framework.
$response = $console->run();
if ($response->getStatusCode() >= 300)
{
exit($response->getStatusCode());
}
3 changes: 2 additions & 1 deletion system/CLI/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class CommandRunner extends Controller
* @param string $method
* @param array ...$params
*
* @return mixed
* @throws \ReflectionException
*/
public function _remap($method, ...$params)
Expand All @@ -81,7 +82,7 @@ public function _remap($method, ...$params)
array_shift($params);
}

$this->index($params);
return $this->index($params);
}

//--------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ protected function handleRequest(RouteCollectionInterface $routes = null, $cache
else
{
$response = $this->response;

// Set response code for CLI command failures
if (is_numeric($returned) || $returned === false)
{
$response->setStatusCode(400);
}
}

if ($response instanceof Response)
Expand Down