This repository was archived by the owner on Jan 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.ts
More file actions
85 lines (74 loc) · 1.79 KB
/
Copy pathcli.ts
File metadata and controls
85 lines (74 loc) · 1.79 KB
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
#! /usr/bin/env node
import { parseArgs } from "node:util";
import { run as runImport } from "./scripts/import.js";
import { run as runFix } from "./scripts/fix.js";
import { run as runReport } from "./scripts/report.js";
import { run as runTransactions } from "./scripts/transactions.js";
import { getConfiguration, Configuration } from "./utils/config.js";
import { hardNo } from "./utils/index.js";
export interface CommandArgs {
input?: string | boolean;
output?: string | boolean;
date?: string | boolean;
year?: string | boolean;
terms?: string | boolean;
account?: string | boolean;
}
const scriptMap: {
[key: string]: (
config: Configuration,
cliArgs: CommandArgs
) => Promise<void> | void;
} = {
import: runImport,
fix: runFix,
report: runReport,
transactions: runTransactions,
};
try {
const parsedArgs = parseArgs({
strict: false,
allowPositionals: true,
options: {
input: {
type: "string",
},
output: {
type: "string",
},
year: {
type: "string",
},
date: {
type: "string",
},
terms: {
type: "string",
},
account: {
type: "string",
},
},
});
const {
values,
positionals,
}: {
values: CommandArgs;
positionals: string[];
} = parsedArgs;
if (!positionals.length) {
throw new Error("Missing budget command");
}
if (positionals.length !== 1) {
throw new Error(`Invalid budget command ${positionals[1]}`);
}
if (!(positionals[0] in scriptMap)) {
throw new Error(`Unknown budget command ${positionals[0]}`);
}
const config = getConfiguration();
const script = scriptMap[positionals[0] as keyof typeof scriptMap];
await script(config, values);
} catch (error: unknown) {
hardNo("Error", error);
}