Skip to content

Commit

Permalink
Sort out exit codes on abend and help.
Browse files Browse the repository at this point in the history
Closes #152.
  • Loading branch information
flatheadmill committed Jul 31, 2016
1 parent 30ae1e5 commit e0ebd7b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
7 changes: 5 additions & 2 deletions exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions program.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion t/exit.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e0ebd7b

Please sign in to comment.