Skip to content

Commit 5d1b3c8

Browse files
committed
feat: switch commands to oclif
1 parent 5433cc9 commit 5d1b3c8

File tree

14 files changed

+595
-642
lines changed

14 files changed

+595
-642
lines changed

.eslintrc.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ module.exports = {
1313
plugins: ["@typescript-eslint"],
1414
root: true,
1515
overrides: [
16+
{
17+
files: ["*"],
18+
rules: {
19+
"@typescript-eslint/require-await": "off",
20+
}
21+
},
1622
{
1723
files: ["*.spec.*"],
1824
rules: {
19-
"@typescript-eslint/no-non-null-assertion": "off"
25+
"@typescript-eslint/no-non-null-assertion": "off",
2026
}
2127
}
2228
]

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"name": "budget-cli",
23
"type": "module",
34
"engines": {
45
"node": ">=18 <=20"
@@ -12,11 +13,7 @@
1213
"prettier": "prettier --write ./src",
1314
"prettier-ci": "prettier --check ./src",
1415
"prettier-watch": "onchange './src/**/*.ts' -- prettier --write --ignore-unknown {{changed}}",
15-
"format": "npm run eslint && npm run prettier",
16-
"import": "node ./dist/src/cli.js import",
17-
"report": "node ./dist/src/cli.js report",
18-
"transactions": "node ./dist/src/cli.js transactions",
19-
"fix": "node ./dist/src/cli.js fix"
16+
"format": "npm run eslint && npm run prettier"
2017
},
2118
"devDependencies": {
2219
"@types/inquirer": "^9.0.3",
@@ -42,7 +39,8 @@
4239
},
4340
"oclif": {
4441
"bin": "money",
45-
"commands": "./dist/commands",
46-
"dirname": "money"
42+
"commands": "./dist/src/commands",
43+
"dirname": "money",
44+
"topicSeparator": ":"
4745
}
48-
}
46+
}

src/cli.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/commands/_base.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Args, Command, Flags, Interfaces } from "@oclif/core";
2+
import { Configuration, getConfiguration } from "../utils/config.js";
3+
4+
////
5+
/// Types
6+
//
7+
8+
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<
9+
(typeof ImportBaseCommand)["baseFlags"] & T["flags"]
10+
>;
11+
12+
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T["args"]>;
13+
14+
////
15+
/// Exports
16+
//
17+
18+
export const importNameArg = {
19+
importName: Args.string({
20+
required: true,
21+
name: "APINAME",
22+
}),
23+
};
24+
25+
export abstract class ImportBaseCommand<T extends typeof Command> extends Command {
26+
static override baseFlags = {};
27+
28+
static override flags = {
29+
year: Flags.string({
30+
char: "y",
31+
summary: "Year to import",
32+
default: `${new Date().getFullYear()}`,
33+
}),
34+
output: Flags.string({
35+
char: "o",
36+
summary: "Path to output CSV",
37+
default: "",
38+
}),
39+
date: Flags.string({
40+
summary: "Date used for filtering",
41+
default: "",
42+
}),
43+
};
44+
45+
protected flags!: Flags<T>;
46+
protected args!: Args<T>;
47+
protected conf!: Configuration;
48+
49+
public override async init(): Promise<void> {
50+
await super.init();
51+
const { args, flags } = await this.parse({
52+
flags: this.ctor.flags,
53+
baseFlags: (super.ctor as typeof ImportBaseCommand).baseFlags,
54+
enableJsonFlag: this.ctor.enableJsonFlag,
55+
args: this.ctor.args,
56+
strict: true,
57+
});
58+
59+
this.flags = flags as Flags<T>;
60+
this.args = args as Args<T>;
61+
this.conf = getConfiguration();
62+
}
63+
64+
protected override async catch(err: Error & { exitCode?: number }) {
65+
await super.catch(err);
66+
}
67+
68+
protected override async finally(_: Error | undefined) {
69+
await super.finally(_);
70+
}
71+
}

0 commit comments

Comments
 (0)