From b5bf5b72ed480d9c3219b6c54d3e102d3b2938b1 Mon Sep 17 00:00:00 2001 From: p-sw Date: Sun, 31 May 2026 23:24:57 +0900 Subject: [PATCH] feat: add basic commands --- src/commands/brain.ts | 2 ++ src/commands/greet.ts | 16 --------------- src/commands/run.ts | 3 +++ src/index.ts | 45 ++++++++++++++++++------------------------- 4 files changed, 24 insertions(+), 42 deletions(-) create mode 100644 src/commands/brain.ts delete mode 100644 src/commands/greet.ts create mode 100644 src/commands/run.ts diff --git a/src/commands/brain.ts b/src/commands/brain.ts new file mode 100644 index 0000000..ac84bd0 --- /dev/null +++ b/src/commands/brain.ts @@ -0,0 +1,2 @@ +// Manage brains +export async function brain() {} diff --git a/src/commands/greet.ts b/src/commands/greet.ts deleted file mode 100644 index cb66e72..0000000 --- a/src/commands/greet.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { logger } from "@/utils/logger"; - -interface GreetOptions { - uppercase?: boolean; - count?: string; -} - -export function greet(name: string, options: GreetOptions) { - const message = `Hello, ${name}!`; - const output = options.uppercase ? message.toUpperCase() : message; - const count = Math.max(1, parseInt(options.count ?? "1", 10)); - - for (let i = 0; i < count; i++) { - logger.success(output); - } -} diff --git a/src/commands/run.ts b/src/commands/run.ts new file mode 100644 index 0000000..418a302 --- /dev/null +++ b/src/commands/run.ts @@ -0,0 +1,3 @@ +// Run brain + +export async function run() {} diff --git a/src/index.ts b/src/index.ts index 26d8588..507513b 100755 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,8 @@ import { readFileSync } from "fs"; import { fileURLToPath } from "url"; import { dirname, join } from "path"; import { logger } from "@/utils/logger"; -import { greet } from "@/commands/greet"; +import { run } from "@/commands/run"; +import { brain } from "@/commands/brain"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -19,32 +20,24 @@ function getVersion(): string { } } -function run(argv: string[] = process.argv) { - const program = new Command(); +const argv = process.argv; +const program = new Command(); - program - .name("brainbox") - .description("A CLI tool for brainbox") - .version(getVersion(), "-v, --version", "Display version number") - .helpOption("-h, --help", "Display help for command") - .configureOutput({ - outputError: (str) => logger.error(str.replace("error: ", "")), - }); - - program - .command("greet") - .description("Greet someone") - .argument("", "Name to greet") - .option("-u, --uppercase", "Convert greeting to uppercase") - .option("-c, --count ", "Repeat the greeting", "1") - .action(greet); - - program.on("command:*", () => { - logger.error(`Unknown command: ${program.args.join(" ")}`); - program.help(); +program + .name("brainbox") + .description("A CLI tool for brainbox") + .version(getVersion(), "-v, --version", "Display version number") + .helpOption("-h, --help", "Display help for command") + .configureOutput({ + outputError: (str) => logger.error(str.replace("error: ", "")), }); - program.parse(argv); -} +program.command("run").description("Run BrainBox").action(run); +program.command("brain").description("Manage brains").action(brain); -run(); +program.on("command:*", () => { + logger.error(`Unknown command: ${program.args.join(" ")}`); + program.help(); +}); + +program.parse(argv);