-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcli.js
executable file
·49 lines (43 loc) · 938 Bytes
/
cli.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
#!/usr/bin/env node
/* eslint no-console: "off" */
const qif2json = require('./lib/qif2json.js');
const args = process.argv.slice(2);
let transactionsOnly;
let file;
let dateFormat;
while (args.length > 0) {
const arg = args.shift();
if (arg.indexOf('-') !== 0) {
file = arg;
continue;
}
switch (arg) {
case '--transactions':
case '-t':
transactionsOnly = true;
break;
case '--date-format':
case '-d':
dateFormat = args.shift().split(',');
break;
default:
break;
}
}
function output(err, data) {
let finalData = data;
if (err) {
console.error(err.message);
return;
}
if (transactionsOnly) {
finalData = data.transactions;
}
console.log(JSON.stringify(finalData, null, 4));
}
if (!file) {
qif2json.parseStream(process.stdin, { dateFormat }, output);
process.stdin.resume();
} else {
qif2json.parseFile(file, { dateFormat }, output);
}