-
Notifications
You must be signed in to change notification settings - Fork 17
/
cli.js
45 lines (39 loc) · 924 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
const fs = require('fs');
const MT940Parser = require('./lib/parser');
function banner() {
console.log('Usage: node cli.js <filename>');
console.log('--');
console.log(' filename - mt940 text file in UTF8 encoding');
}
const argv = process.argv.slice(2);
let files = [];
if (!argv.length) {
banner();
process.exit(1);
}
argv.forEach(arg => {
switch (arg) {
case '--help':
case '-h':
banner();
process.exit(1);
break;
default:
try {
fs.accessSync(arg);
files.push(arg);
} catch (e) {
console.error(`Cannot access file: ${arg}`);
process.exit(1);
}
}
});
files.forEach(file => {
const parser = new MT940Parser();
const data = fs.readFileSync(file, { encoding: 'utf8' });
const statements = parser.parse(data);
statements.forEach(stmt => {
console.log('--');
console.log(JSON.stringify(stmt, null, ' '));
});
});