diff --git a/src/args.ts b/src/args.ts index 4875e5a7..b5d90fd8 100644 --- a/src/args.ts +++ b/src/args.ts @@ -6,6 +6,7 @@ export type CliCommand = | { kind: "status"; issueKey: string; projectId: string } | { kind: "projects" } | { kind: "setup"; check: boolean } + | { kind: "hello"; name?: string } | { kind: "help" }; export function parseArgs(argv: string[]): CliCommand { @@ -76,6 +77,12 @@ export function parseArgs(argv: string[]): CliCommand { return { kind: "projects" }; } + if (command === "hello") { + const args = rest.slice(1); + const name = readFlagValue(args, "--name"); + return { kind: "hello", name }; + } + throw new Error(`Unknown command: ${command}`); } diff --git a/src/commands/handlers.ts b/src/commands/handlers.ts index 3247cc9c..3d01008d 100644 --- a/src/commands/handlers.ts +++ b/src/commands/handlers.ts @@ -7,7 +7,10 @@ import { runWorkflow } from "../core/workflow"; import { runCronScheduler } from "../services/cron"; type SetupCommand = Extract; -type RunnableCommand = Exclude; +type RunnableCommand = Exclude< + CliCommand, + { kind: "help" } | { kind: "hello" } | SetupCommand +>; export async function handleSetupCommand( command: SetupCommand, @@ -63,6 +66,11 @@ export async function handleCommand( process.stdout.write(`${JSON.stringify(state, null, 2)}\n`); } +export function handleHelloCommand(command: { name?: string }): void { + const target = command.name ?? "World"; + process.stdout.write(`Hello, ${target}!\n`); +} + export function printHelp(): void { process.stdout.write( `${[ @@ -74,6 +82,7 @@ export function printHelp(): void { " adhd-ai cron [--job ]", " adhd-ai status --project --issue ", " adhd-ai projects", + " adhd-ai hello [--name ]", " adhd-ai setup [--check]", " adhd-ai help", "", diff --git a/src/index.ts b/src/index.ts index bbb8657e..6570f202 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { parseArgs } from "./args"; import { handleCommand, + handleHelloCommand, handleSetupCommand, printHelp, } from "./commands/handlers"; @@ -26,6 +27,11 @@ async function main(): Promise { return; } + if (command.kind === "hello") { + handleHelloCommand(command); + return; + } + const config = await loadConfig(cwd); await handleCommand(command, config); } diff --git a/tests/args.test.ts b/tests/args.test.ts index c3b7fbf1..f2e387d1 100644 --- a/tests/args.test.ts +++ b/tests/args.test.ts @@ -143,4 +143,20 @@ describe("parseArgs", () => { ]), ).toThrow("run command cannot use --project with --all-projects"); }); + + it("parses hello command without name", () => { + const parsed = parseArgs(["bun", "adhd-ai", "hello"]); + expect(parsed).toEqual({ + kind: "hello", + name: undefined, + }); + }); + + it("parses hello command with name", () => { + const parsed = parseArgs(["bun", "adhd-ai", "hello", "--name", "Alice"]); + expect(parsed).toEqual({ + kind: "hello", + name: "Alice", + }); + }); });