-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
101 lines (76 loc) · 2.46 KB
/
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
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
const program = require('commander');
var sprintf = require("sprintf-js").sprintf;
program.version('0.0.1');
// Commands
program
.command('register')
.alias('reg')
.description('List all postings matching the report-query. ')
.action(function() {
if(FileExist()) {
const Register = require("./Register");
Register(array_transactions,program.sort);
}
})
program
.command('balance [arg...]')
.alias('bal')
.description('Print a balance report showing totals for postings that match report-query, and aggregate totals for parents of those accounts')
.action(function (arg) {
if(FileExist()) {
const Balance = require("./Balance");
Balance(array_transactions,arg);
}
})
program
.command('print')
.alias('p')
.description('Print out the full transactions of any matching postings')
.action(function () {
if(FileExist()) {
const Print = require("./Print");
Print(array_transactions,program.sort);
}
})
// Options
program
.option('--price-db' ,'')
.action()
program
.option('-f, --file <path>' ,'Read journal data from FILE.')
.action()
program
.option('-s, --sort <path>' ,'Sort postings by evaluating the given value-expression', 'noOrder')
.action()
program.parse(process.argv);
function FileExist(){
if (program.file) {
const parser = require("./parser");
if (program.file == "index.ledger"){
/* const lineByLine = require('n-readlines');
const liner = new lineByLine(`ledger-sample-files/${program.file}`);
let line;
var includes = []
var inc;
while (line = liner.next()) {
line = line.toString('ascii');
if(line.startsWith("!include ")) {
inc = line.toString().trim()
inc = inc.replace("!include ","");
includes.push(inc)
}
} */
array_transactions = parser("Income.ledger");
console.log(array_transactions);
array_transactions2 = parser("Payable.ledger");
console.log(array_transactions2);
return array_transactions
} else {
array_transactions = parser(program.file);
return array_transactions
}
} else {
console.log("Error: No journal file was specified (please use -f) ");
return false;
}
}