From 26663377fd7ea15a6c3d23a399d1266c8639d42e Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 31 May 2017 18:58:08 -0300 Subject: Progress --- src/process-argv.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/process-argv.js') 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) } }) -- cgit 1.3.0-6-gf8a5