Commit 8725ae5d authored by Aaron Wells's avatar Aaron Wells
Browse files

Allow CLI api to directly specify Unix process return code

Bug1275617. Existing code only accept a boolean value for the $error
parameter, and return 0 or 127 for success or failure. This patch
allows you to pass an int for the $error parameter, in which case
that int is used as the return code. If you pass a boolean, we use
the old 0/127 behavior.

Change-Id: I96637f9c896184dc36c51bb968284f47f4fbc864
parent baffe7aa
......@@ -358,9 +358,10 @@ class cli {
* Exit the program with a message and set the exit status appropriately
* @param string $message The message to output
* @param mixed $error false if exiting normally; true or the expected
* error code if exiting abnormally. If true is used, then an exit code of
* 127 is used
* @param int|bool $error (default boolean false) Indicates whether this is an error exit.
* If boolean false, exit code 0 (success).
* If boolean true, exit code 127 (failure)
* If an integer value is passed, use the integer as the exit code.
* @return void
public function cli_exit($message = null, $error = false) {
......@@ -368,10 +369,13 @@ class cli {
print($message . "\n");
if ($error === false) {
if (is_int($error)) {
$exitcode = $error;
else if ($error === false) {
$exitcode = 0;
else if ($error === true || !is_int($error)) {
else {
$exitcode = 127;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment