Skip to content

Instantly share code, notes, and snippets.

@gergob gergob/yes.js
Created Jul 18, 2013

Embed
What would you like to do?
Contains the implementation of linux's yes command.
#!/usr/bin/env node
/*
This small node.js app should do exactly what the yes linux command does.
Quote from man yes:
Repeatedly output a line with all specified STRING(s), or `y'.
*/
var DEFAULT_TEXT = "y\n";
var CUSTOM_TEXT = "";
var printUsage = function() {
process.stdout.write("this will contain the details how to use the program\n");
};
var writeDefaultText = function() {
process.stdout.write(DEFAULT_TEXT);
};
var writerCustomText = function() {
process.stdout.write(CUSTOM_TEXT);
};
//handler for CTRL + C
process.on("SIGINT", function() {
clearInterval(writeDefaultText);
clearInterval(writerCustomText);
process.exit(0);
});
if(process.argv.length == 2) {
setInterval(writeDefaultText, 2);
}
else if(process.argv.length == 3) {
CUSTOM_TEXT = process.argv[2];
if(CUSTOM_TEXT[CUSTOM_TEXT.length - 1] != "\n") {
CUSTOM_TEXT += "\n";
}
setInterval(writerCustomText, 2);
}
else {
printUsage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.