« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/gen-thumbs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/gen-thumbs.js')
-rw-r--r--src/gen-thumbs.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js
index d636d2f..e6dfeae 100644
--- a/src/gen-thumbs.js
+++ b/src/gen-thumbs.js
@@ -100,6 +100,7 @@ import {
 } from './util/cli.js';
 
 import {
+    isMain,
     promisifyProcess,
 } from './util/node-utils.js';
 
@@ -304,3 +305,29 @@ export default async function genThumbs(mediaPath, {
 
     return true;
 }
+
+if (isMain(import.meta.url)) {
+    (async function() {
+        const miscOptions = await parseOptions(process.argv.slice(2), {
+            'media-path': {
+                type: 'value'
+            },
+            'queue-size': {
+                type: 'value',
+                validate(size) {
+                    if (parseInt(size) !== parseFloat(size)) return 'an integer';
+                    if (parseInt(size) < 0) return 'a counting number or zero';
+                    return true;
+                }
+            },
+            queue: {alias: 'queue-size'},
+        });
+
+        const mediaPath = miscOptions['media-path'] || process.env.HSMUSIC_MEDIA;
+        const queueSize = +(miscOptions['queue-size'] ?? 0);
+
+        await genThumbs(mediaPath, {queueSize});
+    })().catch(err => {
+        console.error(err);
+    });
+}