-
Notifications
You must be signed in to change notification settings - Fork 6
/
options.js
111 lines (107 loc) · 3.96 KB
/
options.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict'
var fs = require('fs')
class Options {
constructor () {
this.destdir = '.'
this.indent = false
this.ltsprefix = 'level_'
this.osmfilename = ''
this.model = 'default'
this.verbose = false
this.zero = false
this.names = false
}
usage () {
console.log('Open Street Map Cycling Stress Analyzer')
console.log(' ')
console.log('Usage: ltsanalyzer [OPTION] -f FILE')
console.log('Accepts an .osm FILE containing way and node information for ')
console.log('a region and outputs a set of GeoJSON stress level files containing ')
console.log('the ways that correspond to each calculated stress level.')
console.log(' ')
console.log('Mandatory arguments to long options are mandatory for short options too. ')
console.log(' -d, --destdir Directory where all output files will be created.')
console.log(' -f, --filename=NAME Filename is path to the OSM XML input file.')
console.log(' -h, --help Displays this help and exits.')
console.log(' -i, --indent Indent the output files in a readable format.')
console.log(' -m, --model=MODEL Specifies the model to be used. The default is stressmodel.')
console.log(' -n, --names Include the way names in the output.')
console.log(' -p, --prefix=PREFIX The prefix to be used for all output files. The')
console.log(' default is "level_".')
console.log(' -v, --verbose Enables verbose output.')
console.log(' -z, --zero Generate zero level file containing all ways')
console.log(' where cycling is not permitted.')
}
Load (args) {
var help = false
for (var i = 2; i < args.length; i++) {
var arg = args[i].trim().toLowerCase()
if (arg === '-f' || arg === '--filename') {
if (args.length >= i) {
i++
this.osmfilename = args[i]
} else {
console.log('Error: -f command line argument must be followed by a file path.')
return false
}
} else if (arg === '-d' || arg === '--destdir') {
if (args.length >= i) {
i++
this.destdir = args[i]
} else {
console.log('Error: -f command line argument must be followed by a file path.')
return false
}
} else if (arg === '-i' || arg === '--indent') {
this.indent = true
} else if (arg === '-h' || arg === '--help') {
help = true
} else if (arg === '-n' || arg === '--names') {
this.names = true
} else if (arg === '-p' || arg === '--prefix') {
if (args.length >= i) {
i++
this.ltsprefix = args[i]
} else {
console.log('Error: -p command line argument must be followed by a file prefix.')
return false
}
} else if (arg === '-m' || arg === '--model') {
if (args.length >= i) {
i++
if (args[i][0] !== '-') {
this.model = args[i]
} else {
console.log('Error: -m command line argument must be followed by a model specification.')
return false
}
}
else {
console.log('Error: -m command line argument must be followed by a model specification.')
return false
}
} else if (arg === '-v' || arg === '--verbose') {
this.verbose = true
} else if (arg === '-z' || arg === '--zero') {
this.zero = true
} else {
console.log('Unknown option "' + arg + '". Try --help for more information.')
return false
}
}
if (help) {
this.usage()
return false
} else if (this.osmfilename.length === 0 || this.ltsprefix.length === 0) {
this.usage()
return false
} else {
if (!fs.existsSync(this.osmfilename)) {
console.log('Error: File "' + this.osmfilename + '" does not exist.')
return false
}
}
return true
}
}
module.exports = Options