Skip to content

Instantly share code, notes, and snippets.

@ralt
Created May 11, 2015 21:24
Show Gist options
  • Save ralt/175773e9ed450fd938ae to your computer and use it in GitHub Desktop.
Save ralt/175773e9ed450fd938ae to your computer and use it in GitHub Desktop.
var stdin = process.openStdin();
stdin.on('data', parse);
var commands = {};
function parse(it) {
var parts = it.split(' ');
var commandIdx = Object.keys(commands).indexOf(parts[0]);
if (commandIdx > -1) {
commands[commandIdx].apply(null, parts.slice(1));
}
else {
console.log('Command not found');
}
}
commands['adder'] = function() {
console.log([].slice.call(arguments).reduce(function(a, b) { return a + b; }, 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment