Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse alternate to `process.argv`. IF/ELSE loads from CLI and loads from inclusion in another script
/*
initialize from alternate in CLI commander.js script
Included as a module in nodejs
instead of process.argv
https://github.com/tj/commander.js/
*/
if (require.main === module) {
// node module_initialized.commander.js --some_arg --another
program.parse(process.argv);
} else {
/*
process.argv arguments *may* not be ideal,
conflicting or broken when included as module.
ex: access the script file as a module
const tools = require("module_initialized.commander.js");
*/
_.extend(module.exports, {
parse:function(args) {
program.parse(args);
}
});
}
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.