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