-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandLine.mjs
58 lines (55 loc) · 1.52 KB
/
commandLine.mjs
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
'use strict';
import {getLogger} from './src/logger.mjs';
import {getRelation} from './src/osm2gpx.mjs';
import {writeFileSync} from 'fs';
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs';
const logger = getLogger('commandLine');
const args = yargs(hideBin(process.argv))
.usage('Usage: $0 <command> [options]')
.example(
'node $0 -r 282071',
'Exports the Israel National Trail into a gpx file',
)
.command({
command: 'getRelation [relationId]',
description: 'Exports the relation to a gpx file',
async handler(argv) {
try {
const {fileName, gpx} = await getRelation(argv);
writeFileSync(fileName, gpx);
logger.info(`Done writing file "${fileName}"`)
} catch (error) {
logger.error(error);
}
},
})
.options({
r: {
alias: 'relationId',
demandOption: true,
describe: 'Open Street Maps Relation Id to export',
type: 'number',
},
s: {
alias: 'segmentLimit',
default: 9000,
describe: 'The maximum number of waypoints for each gpx track',
type: 'number',
},
m: {
alias: 'markerDiff',
default: 1000,
describe: 'The distance between markers. "0" to disable markers',
type: 'number',
},
rev: {
alias: 'reverse',
default: false,
describe: 'Reverse way sort and marker order',
type: 'boolean',
},
})
.help('h')
.alias('h', 'help')
.epilog('copyright 2015').argv;