From e0ebd7b57d03e73071f14007c9845364791efc6b Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Sun, 31 Jul 2016 14:20:09 -0500 Subject: [PATCH] Sort out exit codes on `abend` and `help`. Closes #152. --- exit.js | 7 +++++-- program.js | 12 ++++-------- t/exit.t.js | 3 ++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exit.js b/exit.js index 363d1db..5cc3ad4 100644 --- a/exit.js +++ b/exit.js @@ -15,15 +15,18 @@ module.exports = function (process) { process.stderr.write(error.stderr) process.stderr.write('\n') } - return error.exitCode || 1 + return error.exitCode }, /^bigeasy.arguable#help$/m, function () { process.stdout.write(error.stdout) process.stdout.write('\n') - return error.exitCode || 0 + return error.exitCode } // TODO Where is exit? ])(error) + if (exitCode == null) { + exitCode = 1 + } } // TODO We ignore this now. It is always set thorugh `program`. if (exitCode != null) { diff --git a/program.js b/program.js index 5aa0374..73a25b8 100644 --- a/program.js +++ b/program.js @@ -255,13 +255,10 @@ Program.prototype.format = function (key) { // abend helper stops execution and prints a message Program.prototype.abend = function () { - var vargs = slice.call(arguments), key = vargs.shift(), code + var vargs = slice.call(arguments), key = vargs.shift(), exitCode = 1 if (typeof key == 'number') { - // **TODO** `_exitCode` looks unused. - this._exitCode = key + exitCode = key key = vargs.shift() - } else { - this._exitCode = 1 } var message if (key) { @@ -275,20 +272,19 @@ Program.prototype.abend = function () { key: key, vargs: vargs, stderr: message, - exitCode: this._exitCode + exitCode: exitCode } }) } // Stop execution and print help message. Program.prototype.help = function () { - this._exitCode = 0 throw interrupt({ name: 'help', context: { method: 'help', stdout: this._usage.chooseUsage(this.lang), - exitCode: this._exitCode + exitCode: 0 } }) } diff --git a/t/exit.t.js b/t/exit.t.js index 568c59b..a113636 100644 --- a/t/exit.t.js +++ b/t/exit.t.js @@ -29,7 +29,8 @@ function prove (assert) { exit(process)(interrupt({ name: 'help', context: { - stdout: 'usage' + stdout: 'usage', + exitCode: 0 } })) assert(process.stdout.read().toString(), 'usage\n', 'help message')