Skip to content

Commit 16f01b2

Browse files
steipetePeter Steinberger
andauthored
refactor: modularize ClawSweeper and keep fix reviews read-only (#979)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent 3637a94 commit 16f01b2

12 files changed

Lines changed: 5507 additions & 4804 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { UserFacingCommandError } from "./command.js";
2+
3+
export type CommandHandler<Args> = (args: Args) => void | Promise<void>;
4+
5+
export async function dispatchCommand<Args>(
6+
command: string,
7+
args: Args,
8+
handlers: Readonly<Record<string, CommandHandler<Args>>>,
9+
): Promise<void> {
10+
if (!Object.hasOwn(handlers, command)) {
11+
throw new UserFacingCommandError(`Unknown command: ${command}`);
12+
}
13+
const handler = handlers[command];
14+
if (!handler) throw new UserFacingCommandError(`Unknown command: ${command}`);
15+
await handler(args);
16+
}

0 commit comments

Comments
 (0)