1#!/usr/bin/env bun
2import { runWebCommand } from "./commands/web.js";
3import { runRepoCommand } from "./commands/repo.js";
4import { RumiloError } from "../util/errors.js";
5
6import { parseArgs } from "./parse-args.js";
7
8async function main() {
9 const { command, options, positional } = parseArgs(process.argv);
10
11 if (!command || command === "help") {
12 console.log("rumilo web <query> [-u URL] [--model <provider:model>] [--verbose] [--no-cleanup]");
13 console.log("rumilo repo -u <uri> <query> [--ref <ref>] [--full] [--model <provider:model>] [--verbose] [--no-cleanup]");
14 process.exit(0);
15 }
16
17 try {
18 if (command === "web") {
19 const query = positional.join(" ");
20 if (!query) {
21 throw new RumiloError("Missing query", "CLI_ERROR");
22 }
23
24 await runWebCommand({
25 query,
26 url: options["uri"] ? String(options["uri"]) : undefined,
27 model: options["model"] ? String(options["model"]) : undefined,
28 verbose: Boolean(options["verbose"]),
29 cleanup: !options["no-cleanup"],
30 });
31 return;
32 }
33
34 if (command === "repo") {
35 const query = positional.join(" ");
36 const uri = options["uri"] ? String(options["uri"]) : undefined;
37 if (!uri) {
38 throw new RumiloError("Missing repo URI", "CLI_ERROR");
39 }
40 if (!query) {
41 throw new RumiloError("Missing query", "CLI_ERROR");
42 }
43
44 await runRepoCommand({
45 query,
46 uri,
47 ref: options["ref"] ? String(options["ref"]) : undefined,
48 full: Boolean(options["full"]),
49 model: options["model"] ? String(options["model"]) : undefined,
50 verbose: Boolean(options["verbose"]),
51 cleanup: !options["no-cleanup"],
52 });
53 return;
54 }
55
56 throw new RumiloError(`Unknown command: ${command}`, "CLI_ERROR");
57 } catch (error: any) {
58 const message = error instanceof Error ? error.message : String(error);
59 console.error(message);
60 process.exitCode = 1;
61 }
62}
63
64main();