Guest User

Untitled

a guest
Dec 16th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const DEFAULT_FLAG = '--options='
  2.  
  3. /**
  4. * Allow to pass additional flag in command line
  5. * @param {String} flag - optionnal flag used in command line
  6. *
  7. * Flags can be passed :
  8. * - either when defining the script in package.json :
  9. * "myscript": "somecommand param --options=opt1"
  10. * - when calling the script adding '--'
  11. * > yarn run myscript -- --options=opt1,opt2
  12. */
  13. function getOptions(flag = DEFAULT_FLAG) {
  14. return process.argv.slice(2)
  15. .filter(arg => arg.startsWith(flag))
  16. .map(arg => arg.replace(flag, '').split(','))
  17. }
  18.  
  19. module.exports = {
  20. getOptions
  21. }
Add Comment
Please, Sign In to add comment