Skip to content

Instantly share code, notes, and snippets.

@grantmiiller
Created February 19, 2014 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantmiiller/9100855 to your computer and use it in GitHub Desktop.
Save grantmiiller/9100855 to your computer and use it in GitHub Desktop.
function resolved(arg) {
console.log('New arg is: ' + arg);
}
function otherCommand(command, argParse, resolve) {
this.errFlag = false;
this.command = command;
this.argParse = argParse;
this.resolve = resolve;
}
otherCommand.prototype.error = function(arg) {
console.log('There was an error: ' + arg);
}
otherCommand.prototype.run = function(arg) {
var input = arg.toString().trim();
param = parseInt(input, 10);
param = this.argParse(param);
if(!this.errFlag) {
this.resolve(param);
} else {
this.errFlag = false;
this.error(param);
}
};
var myOtherCommand = new otherCommand('open', function(arg) {
if(arg !== 0) {
this.errFlag = true;
return arg;
} else {
arg++;
return arg;
}
}, resolved);
process.stdout.write('Please provide input: ');
process.stdin.on('data', function(data) {
myOtherCommand.run(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment