Last active
December 2, 2018 11:47
-
-
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
This file contains 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