Skip to content
Browse files

process.exit() with 0 or 1 depending on `err`

  • Loading branch information...
1 parent c176385 commit 0aaeabf2a5f81dc674d60004894d5fef557ed374 @rvagg rvagg committed Mar 14, 2012
Showing with 8 additions and 5 deletions.
  1. +3 −1 bin/ender
  2. +5 −4 lib/main.js
View
4 bin/ender
@@ -1,3 +1,5 @@
#!/usr/bin/env node
-require('../lib/main').exec(process.argv)
+require('../lib/main').exec(process.argv, function (err) {
+ process.exit(err ? 1 : 0)
+})
View
9 lib/main.js
@@ -3,27 +3,28 @@ var sysUtil = require('util')
, Output = require('./output')
, EnderError = require('./errors').EnderError
- , complete = function (out, err) {
+ , complete = function (out, callback, err) {
if (err) {
if (err instanceof EnderError)
out.enderError(err)
else
out.unknownError(err)
}
+ callback(err)
}
- , exec = function (argv) {
+ , exec = function (argv, callback) {
try {
var args = argsParse.parse(argv)
, exe = args && require('./main-' + args.main)
, out = args && require('./main-' + args.main + '-output').create(sysUtil, args.debug)
if (exe && out) {
out.welcome()
- exe.exec(args, out, complete.bind(null, out))
+ exe.exec(args, out, complete.bind(null, out, callback))
} // else err?
} catch (ex) {
- complete(Output.create(sysUtil, argv.indexOf('--debug') != -1), ex)
+ complete(Output.create(sysUtil, argv.indexOf('--debug') != -1), callback, ex)
}
}

0 comments on commit 0aaeabf

Please sign in to comment.
Something went wrong with that request. Please try again.