diff options
Diffstat (limited to 'src/process-argv.js')
-rw-r--r-- | src/process-argv.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/process-argv.js b/src/process-argv.js index 3193d98..d5f86f9 100644 --- a/src/process-argv.js +++ b/src/process-argv.js @@ -1,17 +1,35 @@ 'use strict' module.exports = async function processArgv(argv, handlers) { + // Basic command line argument list processor. Takes a list of arguments and + // an object, which is used as a mapping of option strings to behavior + // functions. + let i = 0 async function handleOpt(opt) { + // Handles a single option. May be recursive, depending on the user-defined + // handler given to processArgv. If there is no such handler for the given + // option, a warning message is displayed and the option is ignored. + if (opt in handlers) { await handlers[opt]({ + // Util object; stores useful information and methods that the handler + // can access. + argv, index: i, + nextArg: function() { + // Returns the next argument in the argument list, and increments + // the parse index by one. + i++ return argv[i] }, + alias: function(optionToRun) { + // Runs the given option's handler. + handleOpt(optionToRun) } }) |