Permalink
Browse files

fixed the hidden error exit code issue

  • Loading branch information...
1 parent 08d32f1 commit 3ea0b3b19693039a4f21bcaa2cf1550b9ce442a6 @substack substack committed Dec 17, 2013
Showing with 34 additions and 18 deletions.
  1. +23 −18 bin/cmd.js
  2. +11 −0 problems/duplexer_redux/solution.js
View
@@ -1,17 +1,21 @@
#!/usr/bin/env node
+
var argv = require('optimist').argv;
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
-var dataDir = path.resolve(process.env.HOME || process.env.USERPROFILE, '.config/stream-adventure');
+var dataDir = path.resolve(
+ process.env.HOME || process.env.USERPROFILE,
+ '.config/stream-adventure'
+);
+
mkdirp.sync(dataDir);
var exitCode = 0;
process.on('exit', function (code) {
- process.exit(code || exitCode);
+ if (code === 0 && exitCode) process.exit(exitCode);
});
-var showMenu = require('./menu.js');
var verify = require('./verify.js');
var order = require('../data/order.json');
@@ -117,25 +121,26 @@ if (argv._[0] === 'verify' || argv._[0] === 'run') {
}
}
else {
- var opts = {
- completed: getData('completed') || []
- };
+ var opts = {
+ completed: getData('completed') || []
+ };
- if (argv.b || argv.bg){
- opts.bg = argv.b || argv.bg;
- }
+ if (argv.b || argv.bg){
+ opts.bg = argv.b || argv.bg;
+ }
- if (argv.f || argv.fg){
- opts.fg = argv.f || argv.fg;
- }
+ if (argv.f || argv.fg){
+ opts.fg = argv.f || argv.fg;
+ }
- var menu = showMenu(opts);
+ var showMenu = require('./menu.js');
+ var menu = showMenu(opts);
- menu.on('select', onselect);
- menu.on('exit', function () {
- console.log();
- process.exit(0);
- });
+ menu.on('select', onselect);
+ menu.on('exit', function () {
+ console.log();
+ process.exit(0);
+ });
}
function onselect (name) {
@@ -0,0 +1,11 @@
+var duplexer = require('duplexer');
+var through = require('through');
+
+module.exports = function (counter) {
+ var bytes = 0;
+ var input = through(write, end);
+ return duplexer(input, counter);
+
+ function write (buf) { bytes += buf.length }
+ function end () { counter.set(bytes) }
+};

0 comments on commit 3ea0b3b

Please sign in to comment.