« get me outta code hell

Update JS to have one main http-music command - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/crawl-http.js
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-07-20 18:55:18 -0300
committerliam4 <towerofnix@gmail.com>2017-07-20 18:55:18 -0300
commit1a02fe1688d66aea6277f61fcc305a6aed4e7d76 (patch)
tree6e64e928acf81af89fd7f0e802d94eb0c844a63e /src/crawl-http.js
parent2680ea9126499fb775b699f1dbd4ac9aacbc4e4a (diff)
Update JS to have one main http-music command
Diffstat (limited to 'src/crawl-http.js')
-rwxr-xr-xsrc/crawl-http.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/crawl-http.js b/src/crawl-http.js
index a2bf884..29c59d2 100755
--- a/src/crawl-http.js
+++ b/src/crawl-http.js
@@ -139,14 +139,20 @@ function getHTMLLinks(text) {
   })
 }
 
-async function main() {
-  let url = process.argv[2]
+async function main(args) {
+  if (args.length === 0) {
+    console.log("Usage: crawl-http http://.../example/path/ [opts]")
+    process.exit(1)
+    return
+  }
+
+  let url = args[0]
 
   let maxDownloadAttempts = 5
   let verbose = false
   let filterRegex = null
 
-  await processArgv(process.argv.slice(3), {
+  await processArgv(args.slice(1), {
     '-max-download-attempts': function(util) {
       // --max-download-attempts <max>  (alias: -m)
       // Sets the maximum number of times to attempt downloading the index for
@@ -190,9 +196,9 @@ async function main() {
   console.log(JSON.stringify(downloadedPlaylist, null, 2))
 }
 
-if (process.argv.length === 2) {
-  console.log("Usage: http-music-crawl-http http://.../example/path/ [opts]")
-} else {
-  main()
+module.exports = main
+
+if (require.main === module) {
+  main(process.argv.slice(2))
     .catch(err => console.error(err))
 }