Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const DEFAULT_FLAG = '--options='
- /**
- * Allow to pass additional flag in command line
- * @param {String} flag - optionnal flag used in command line
- *
- * Flags can be passed :
- * - either when defining the script in package.json :
- * "myscript": "somecommand param --options=opt1"
- * - when calling the script adding '--'
- * > yarn run myscript -- --options=opt1,opt2
- */
- function getOptions(flag = DEFAULT_FLAG) {
- return process.argv.slice(2)
- .filter(arg => arg.startsWith(flag))
- .map(arg => arg.replace(flag, '').split(','))
- }
- module.exports = {
- getOptions
- }
Add Comment
Please, Sign In to add comment