« get me outta code hell

cli.js « src - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/cli.js
blob: 4bc64abd1976485f0775cf7e1c2b0446901914d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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 'crawl-youtube': script = require('./crawl-youtube'); 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))
}