« get me outta code hell

Progress - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/process-argv.js
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-05-31 18:58:08 -0300
committerLiam <towerofnix@gmail.com>2017-05-31 18:58:08 -0300
commit26663377fd7ea15a6c3d23a399d1266c8639d42e (patch)
treefa0532caaf5672501bb5797499a515da72a09038 /src/process-argv.js
parent42ec01bb91c517067a9eba901272c1248ed52261 (diff)
Progress
Diffstat (limited to 'src/process-argv.js')
-rw-r--r--src/process-argv.js18
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)
         }
       })