Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}`);
}

Expand Down
11 changes: 10 additions & 1 deletion src/commands/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { runWorkflow } from "../core/workflow";
import { runCronScheduler } from "../services/cron";

type SetupCommand = Extract<CliCommand, { kind: "setup" }>;
type RunnableCommand = Exclude<CliCommand, { kind: "help" } | SetupCommand>;
type RunnableCommand = Exclude<
CliCommand,
{ kind: "help" } | { kind: "hello" } | SetupCommand
>;

export async function handleSetupCommand(
command: SetupCommand,
Expand Down Expand Up @@ -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(
`${[
Expand All @@ -74,6 +82,7 @@ export function printHelp(): void {
" adhd-ai cron [--job <JOB_ID>]",
" adhd-ai status --project <PROJECT_ID> --issue <LINEAR_KEY>",
" adhd-ai projects",
" adhd-ai hello [--name <NAME>]",
" adhd-ai setup [--check]",
" adhd-ai help",
"",
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { parseArgs } from "./args";
import {
handleCommand,
handleHelloCommand,
handleSetupCommand,
printHelp,
} from "./commands/handlers";
Expand All @@ -26,6 +27,11 @@ async function main(): Promise<void> {
return;
}

if (command.kind === "hello") {
handleHelloCommand(command);
return;
}

const config = await loadConfig(cwd);
await handleCommand(command, config);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
});
});
Loading