« 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/cli.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.js')
-rw-r--r--src/cli.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cli.js b/src/cli.js
new file mode 100644
index 0000000..d88ddc0
--- /dev/null
+++ b/src/cli.js
@@ -0,0 +1,37 @@
+#!/usr/bin/env node
+
+// Let this forever be of use to people who run into
+// maxlistenersexceededwarning.
+process.on('warning', e => console.warn(e.stack))
+
+async function main(args) {
+  let script
+
+  if (args.length === 0) {
+    console.error("No command provided.")
+    console.error("Try 'man http-music'?")
+    return
+  }
+
+  switch (args[0]) {
+    case 'play': script = require('./play'); break
+    case 'crawl-http': script = require('./crawl-http'); break
+    case 'crawl-local': script = require('./crawl-local'); break
+    case 'crawl-itunes': script = require('./crawl-itunes'); break
+    case 'download-playlist': script = require('./download-playlist'); break
+
+    default:
+      console.error(`Invalid command "${args[0]}" provided.`)
+      console.error("Try 'man http-music'?")
+      return
+  }
+
+  await script(args.slice(1))
+}
+
+module.exports = main
+
+if (require.main === module) {
+  main(process.argv.slice(2))
+    .catch(err => console.error(err))
+}