Last active
December 2, 2018 11:47
Parse alternate to `process.argv`. IF/ELSE loads from CLI and loads from inclusion in another script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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