Skip to content

Instantly share code, notes, and snippets.

@shamasis
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamasis/9c010918ec19d239cb31 to your computer and use it in GitHub Desktop.
Save shamasis/9c010918ec19d239cb31 to your computer and use it in GitHub Desktop.
Quick parsing of CLI arguments
/**
* @example
* var args = require('./quickargs.js')(process.argv);
*/
module.exports = function (argv) {
var args = {}, // object to store all key-value argument extraction
lastarg; // args are split by space, so we keep a track of last key detected
argv && argv.slice && argv.slice(2).forEach(function (item) {
lastarg = /^-/.test(item) ? item.slice(1) : (lastarg && (args[lastarg] = item), undefined);
});
return args;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment