« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/util/cli.js26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/util/cli.js b/src/util/cli.js
index 72979d3f..5d314dc4 100644
--- a/src/util/cli.js
+++ b/src/util/cli.js
@@ -95,8 +95,12 @@ export async function parseOptions(options, optionDescriptorMap) {
   // }
   //
   // ['--directory', 'apple'] -> {'directory': 'apple'}
+  // ['--directory=banana'] -> {'directory': 'banana'}
   // ['--directory', 'artichoke'] -> (error)
+  //
   // ['--files', 'a', 'b', 'c', ';'] -> {'files': ['a', 'b', 'c']}
+  // ['--files=a,b,c'] -> {'files': ['a', 'b', 'c']}
+  // ['--files', 'a,b,c'] -> {'files': ['a', 'b', 'c']}
 
   const handleDashless = optionDescriptorMap[parseOptions.handleDashless];
   const handleUnknown = optionDescriptorMap[parseOptions.handleUnknown];
@@ -149,9 +153,27 @@ export async function parseOptions(options, optionDescriptorMap) {
         }
 
         case 'series': {
+          if (option.includes('=')) {
+            result[name] = option.split('=')[1].split(',');
+            break;
+          }
+
+          // without a semicolon to conclude the series,
+          // assume the next option expresses the whole series
           if (!options.slice(i).includes(';')) {
-            console.error(`Expected a series of values concluding with ; (\\;) for --${name}`);
-            process.exit(1);
+            let value = options[++i];
+
+            if (!value || value.startsWith('-')) {
+              value = null;
+            }
+
+            if (!value) {
+              console.error(`Expected values for --${name}`);
+              process.exit(1);
+            }
+
+            result[name] = value.split('=')[1].split(',');
+            break;
           }
 
           const endIndex = i + options.slice(i).indexOf(';');