index.ts

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