-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
journey.js
executable file
·68 lines (58 loc) · 1.9 KB
/
journey.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 createJourneysCli = require('hafas-cli/journeys')
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-journey [origin] [destination] [options]
Arguments:
origin Station number (e.g. 900000023201) or query (e.g. "Zoo").
destination Station number (e.g. 900000023201) or query (e.g. "Zoo").
Options:
--results -r The number of journeys to show. Default: 4
--products -p Allowed transportation types. Default: "all"
"all" = "suburban,subway,tram,bus,ferry,express,regional"
--when -w A date & time string like "tomorrow 2 pm". Default: now
--show-ids Show station & journey leg IDs. Default: false
`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`vbb-journey 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 journeysCli = createJourneysCli(hafas, {
productColor, productSymbol,
lineColor,
showLocationIds: argv['show-ids'], showTripIds: argv['show-ids']
})
journeysCli({
origin: argv._[0],
destination: argv._[1],
results: argv.results || argv.r || 4,
queryResults: (argv.results || argv.r) === 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)