Skip to content

Commit

Permalink
feat: switch commands to oclif
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed May 22, 2024
1 parent 5433cc9 commit 5d1b3c8
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 642 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ module.exports = {
plugins: ["@typescript-eslint"],
root: true,
overrides: [
{
files: ["*"],
rules: {
"@typescript-eslint/require-await": "off",
}
},
{
files: ["*.spec.*"],
rules: {
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-non-null-assertion": "off",
}
}
]
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "budget-cli",
"type": "module",
"engines": {
"node": ">=18 <=20"
Expand All @@ -12,11 +13,7 @@
"prettier": "prettier --write ./src",
"prettier-ci": "prettier --check ./src",
"prettier-watch": "onchange './src/**/*.ts' -- prettier --write --ignore-unknown {{changed}}",
"format": "npm run eslint && npm run prettier",
"import": "node ./dist/src/cli.js import",
"report": "node ./dist/src/cli.js report",
"transactions": "node ./dist/src/cli.js transactions",
"fix": "node ./dist/src/cli.js fix"
"format": "npm run eslint && npm run prettier"
},
"devDependencies": {
"@types/inquirer": "^9.0.3",
Expand All @@ -42,7 +39,8 @@
},
"oclif": {
"bin": "money",
"commands": "./dist/commands",
"dirname": "money"
"commands": "./dist/src/commands",
"dirname": "money",
"topicSeparator": ":"
}
}
}
85 changes: 0 additions & 85 deletions src/cli.ts

This file was deleted.

71 changes: 71 additions & 0 deletions src/commands/_base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Args, Command, Flags, Interfaces } from "@oclif/core";
import { Configuration, getConfiguration } from "../utils/config.js";

////
/// Types
//

export type Flags<T extends typeof Command> = Interfaces.InferredFlags<
(typeof ImportBaseCommand)["baseFlags"] & T["flags"]
>;

export type Args<T extends typeof Command> = Interfaces.InferredArgs<T["args"]>;

////
/// Exports
//

export const importNameArg = {
importName: Args.string({
required: true,
name: "APINAME",
}),
};

export abstract class ImportBaseCommand<T extends typeof Command> extends Command {
static override baseFlags = {};

static override flags = {
year: Flags.string({
char: "y",
summary: "Year to import",
default: `${new Date().getFullYear()}`,
}),
output: Flags.string({
char: "o",
summary: "Path to output CSV",
default: "",
}),
date: Flags.string({
summary: "Date used for filtering",
default: "",
}),
};

protected flags!: Flags<T>;
protected args!: Args<T>;
protected conf!: Configuration;

public override async init(): Promise<void> {
await super.init();
const { args, flags } = await this.parse({
flags: this.ctor.flags,
baseFlags: (super.ctor as typeof ImportBaseCommand).baseFlags,
enableJsonFlag: this.ctor.enableJsonFlag,
args: this.ctor.args,
strict: true,
});

this.flags = flags as Flags<T>;
this.args = args as Args<T>;
this.conf = getConfiguration();
}

protected override async catch(err: Error & { exitCode?: number }) {
await super.catch(err);
}

protected override async finally(_: Error | undefined) {
await super.finally(_);
}
}
Loading

0 comments on commit 5d1b3c8

Please sign in to comment.