-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
executable file
·49 lines (38 loc) · 828 Bytes
/
bin.js
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
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const pkg = require('./package.json')
const play = require('.')
const showUI = require('./lib/ui')
const showError = (err) => {
console.error(err)
process.exit(1)
}
const argv = mri(process.argv.slice(2), {
boolean: [
'help', 'h',
'version', 'v'
]
})
if (argv.h || argv.help) {
process.stdout.write(`\
Play music at co.up coworking Berlin.
Usage:
coup-play <audio-url>
`)
process.exit(0)
}
if (argv.v || argv.version) {
process.stdout.write('coup-play ' + pkg.version + '\n')
process.exit(0)
}
const audioUrl = argv._[0]
if (!audioUrl) showError('Missing audio-url argument.')
const device = play(audioUrl, (err) => {
if (err) showError(err)
})
device.on('error', showError)
process.once('beforeExit', () => {
device.stop()
})
showUI(device)