-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (28 loc) · 1013 Bytes
/
index.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
const program = require('commander');
const { GetMapsObject, GetDirections } = require('./lib');
program
.version('1.0.4')
.description('Convert Google directions URL to a given output format')
.usage('[options] <GoogleMapsDirectionsURL ...>')
.option(
'-K, --key <API_KEY>',
'Google Maps API key (defaults to env variable: GOOGLE_MAPS_API_KEY)',
process.env.GOOGLE_MAPS_API_KEY
)
.option(
'-F, --format <type>',
'Output format: GeoJSON (default), TopoJSON, KML, GPX',
/^(GeoJSON|TopoJSON|KML|GPX)$/i,
'GeoJSON'
)
.parse(process.argv);
// overwrite api key
if (program.key) process.env.GOOGLE_MAPS_API_KEY = program.key;
// if no args or api key not found
if (!program.args.length) program.help();
if (process.env.GOOGLE_MAPS_API_KEY === undefined) {
console.error('Error: Unable to find Google Maps API key');
process.exit(0);
}
// if args then execute main program
if (program.args.length) GetDirections(GetMapsObject(program.args[0]), program.format);