« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/crawl-local.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/crawl-local.js')
-rwxr-xr-xsrc/crawl-local.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/crawl-local.js b/src/crawl-local.js
index 6d245ae..629e015 100755
--- a/src/crawl-local.js
+++ b/src/crawl-local.js
@@ -30,13 +30,20 @@ function crawl(dirPath) {
   }).then(items => ({items}))
 }
 
-if (process.argv.length === 2) {
-  console.log("Usage: http-music-crawl-local /example/path..")
-  console.log("..or, npm run crawl-local /example/path")
-} else {
-  const path = process.argv[2]
-
-  crawl(path)
-    .then(res => console.log(JSON.stringify(res, null, 2)))
+async function main(args) {
+  if (args.length === 0) {
+    console.log("Usage: crawl-local /example/path")
+  } else {
+    const path = args[0]
+
+    const res = await crawl(path)
+    console.log(JSON.stringify(res, null, 2))
+  }
+}
+
+module.exports = main
+
+if (require.main === module) {
+  main(process.argv.slice(2))
     .catch(err => console.error(err))
 }