From 1a02fe1688d66aea6277f61fcc305a6aed4e7d76 Mon Sep 17 00:00:00 2001 From: liam4 Date: Thu, 20 Jul 2017 18:55:18 -0300 Subject: Update JS to have one main http-music command --- src/crawl-http.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/crawl-http.js') 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 (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)) } -- cgit 1.3.0-6-gf8a5