diff --git a/lib/index.js b/lib/index.js index b470866..16b41c0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,8 +33,6 @@ colors = [ , 'greenBright', 'yellowBright', 'cyanBright' ]; -process.on('unhandledRejection', onError); - function onError (err) { console.error(`${chalk.red(err.name)}: ${err.message}`); if(parsed && parsed.traceback) { @@ -42,11 +40,17 @@ function onError (err) { } else { console.error('use --traceback for full stacktrace'); } - return conf.get('exitOnError') ? process.exit( err.code || 1 ) : null; + const code = isFinite(err.code) ? err.code : 1 + + if (conf.get('exitOnError')) { + process.exit(code) + return + } + process.exitCode = code } function onComplete(content) { - typeof content === 'string' && console.log( content ); + typeof content === 'string' && console.log(content); if(conf.get('exitOnContent')) { process.exit(0); } @@ -149,5 +153,4 @@ function run( ){ console.error('unknown command %s', command ); console.error('know commands: %s ', Object.keys( commands ).join(', ') ); - process.exit(0); }