feat: add basic commands
This commit is contained in:
2
src/commands/brain.ts
Normal file
2
src/commands/brain.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Manage brains
|
||||||
|
export async function brain() {}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
src/commands/run.ts
Normal file
3
src/commands/run.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Run brain
|
||||||
|
|
||||||
|
export async function run() {}
|
||||||
17
src/index.ts
17
src/index.ts
@@ -4,7 +4,8 @@ import { readFileSync } from "fs";
|
|||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import { dirname, join } from "path";
|
import { dirname, join } from "path";
|
||||||
import { logger } from "@/utils/logger";
|
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 __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
@@ -19,7 +20,7 @@ function getVersion(): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(argv: string[] = process.argv) {
|
const argv = process.argv;
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
|
|
||||||
program
|
program
|
||||||
@@ -31,13 +32,8 @@ function run(argv: string[] = process.argv) {
|
|||||||
outputError: (str) => logger.error(str.replace("error: ", "")),
|
outputError: (str) => logger.error(str.replace("error: ", "")),
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program.command("run").description("Run BrainBox").action(run);
|
||||||
.command("greet")
|
program.command("brain").description("Manage brains").action(brain);
|
||||||
.description("Greet someone")
|
|
||||||
.argument("<name>", "Name to greet")
|
|
||||||
.option("-u, --uppercase", "Convert greeting to uppercase")
|
|
||||||
.option("-c, --count <number>", "Repeat the greeting", "1")
|
|
||||||
.action(greet);
|
|
||||||
|
|
||||||
program.on("command:*", () => {
|
program.on("command:*", () => {
|
||||||
logger.error(`Unknown command: ${program.args.join(" ")}`);
|
logger.error(`Unknown command: ${program.args.join(" ")}`);
|
||||||
@@ -45,6 +41,3 @@ function run(argv: string[] = process.argv) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
program.parse(argv);
|
program.parse(argv);
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
|
|||||||
Reference in New Issue
Block a user