-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathinvesting-list.js
36 lines (29 loc) · 1.02 KB
/
investing-list.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
var program = require('commander');
var commodities = require('./investing-commodities');
// ================= parse program arguments
program.version('0.0.1')
.option('-c --country [UK|US]', 'list only commodities from the given country')
.option('-r --regex [search]', 'find commodities with names matching regex. Example: ca, \d, "[cad]a"')
.parse(process.argv);
var cm = commodities.commodities;
if (program.country) {
if (program.country.toUpperCase() === 'US') {
cm = commodities.usOnly();
} else if (program.country.toUpperCase() === 'UK') {
cm = commodities.ukOnly();
} else {
console.error('unknown country', program.country);
process.exit(1);
}
}
if (program.regex) {
cm = commodities.find(new RegExp(program.regex, "i"));
if (cm.length === 0) {
console.error('no commodity matching', program.regex);
process.exit(0);
}
}
for (var i = 0; i < cm.length; i++) {
var o = cm[i];
console.log(o.name, "(" + o.country + ") :", o.id);
}