-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
executable file
·47 lines (38 loc) · 979 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
#!/usr/bin/env node
'use strict'
const minimist = require('minimist')
const monitor = require('db-monitor')
const ndjson = require('ndjson')
const argv = minimist(process.argv.slice(2))
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
db-monitor [--interval milliseconds] station-id [...]
Options:
--interval <ms> How often to query for each station.
Examples:
db-monitor 8011167
db-monitor --interval 5000 8011167 8002553
\n`)
process.exit(0)
}
let interval = argv.interval || argv.i || null
if (interval) {
interval = parseInt(interval)
if (Number.isNaN(interval)) {
process.stdout.write('--interval must be a number.')
process.exit(1)
}
}
const stations = argv._.map((id) => id + '')
if (stations.length === 0) {
process.stdout.write('One or more station IDs must be given.')
process.exit(1)
}
const src = monitor(stations, interval)
src
.pipe(ndjson.stringify())
.pipe(process.stdout)
process.on('SIGINT', () => {
src.stop()
})