Skip to content

Instantly share code, notes, and snippets.

@gtzilla
Last active December 2, 2018 11:47
Show Gist options
  • Save gtzilla/da47fd49ddd04f8a7d74c87e1a952b39 to your computer and use it in GitHub Desktop.
Save gtzilla/da47fd49ddd04f8a7d74c87e1a952b39 to your computer and use it in GitHub Desktop.
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