-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdep.js
executable file
·68 lines (58 loc) · 1.88 KB
/
dep.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const chalk = require('chalk')
const createDeparturesCli = require('hafas-cli/departures')
const pkg = require('./package.json')
const hafas = require('./lib/hafas')
const productColor = require('./lib/product-color')
const productSymbol = require('./lib/product-symbol')
const lineColor = require('./lib/line-color')
const argv = mri(process.argv.slice(2), {
boolean: [
'help', 'h',
'version', 'v',
'location', 'l',
'show-ids'
]
})
if (argv.help || argv.h) {
process.stdout.write(`
vbb-dep [station] [options]
Arguments:
station Station number (like "900000023201") or search string (like "Zoo").
Options:
--location -l Use current location. OS X only.
--duration -d Show departures for the next n minutes. Default: 15
--when -w A date & time string like "tomorrow 2 pm". Default: now
--products -p Allowed transportation types.
Default: suburban,subway,tram,bus,ferry,express,regional
--show-ids Show station & journey leg IDs. Default: false
`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`vbb-dep v${pkg.version}\n`)
process.exit(0)
}
const showError = function (err) {
if (process.env.NODE_DEBUG === 'vbb-cli') console.error(err)
else process.stderr.write(chalk.red(err.message || (err + '')) + '\n')
process.exit(err.code || 1)
}
const departuresCli = createDeparturesCli(hafas, {
productColor, productSymbol,
lineColor,
showLocationIds: argv['show-ids'], showTripIds: argv['show-ids']
})
departuresCli({
station: argv._[0],
useCurrentLocation: argv.location || argv.l,
duration: argv.duration || argv.d,
queryDuration: (argv.duration || argv.d) === true,
when: argv.when || argv.w,
queryWhen: (argv.when || argv.w) === true,
products: argv.products || argv.p,
queryProducts: (argv.products || argv.p) === true
})
.catch(showError)