aboutsummaryrefslogtreecommitdiffstats
path: root/apps/cli/src/index.ts
blob: 7d6c14729ba6ea94cad9b1605be58c17091eba80 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#! /usr/bin/env node
import { bookmarkCmd } from "@/commands/bookmarks";
import { listsCmd } from "@/commands/lists";
import { tagsCmd } from "@/commands/tags";
import { whoamiCmd } from "@/commands/whoami";
import { setGlobalOptions } from "@/lib/globals";
import { Command, Option } from "@commander-js/extra-typings";

const program = new Command()
  .name("karakeep")
  .description("A CLI interface to interact with the karakeep api")
  .addOption(
    new Option("--api-key <key>", "the API key to interact with the API")
      .makeOptionMandatory(true)
      .env("KARAKEEP_API_KEY"),
  )
  .addOption(
    new Option(
      "--server-addr <addr>",
      "the address of the server to connect to",
    )
      .makeOptionMandatory(true)
      .env("KARAKEEP_SERVER_ADDR"),
  )
  .addOption(new Option("--json", "to output the result as JSON"))
  .version(
    import.meta.env && "CLI_VERSION" in import.meta.env
      ? import.meta.env.CLI_VERSION
      : "0.0.0",
  );

program.addCommand(bookmarkCmd);
program.addCommand(listsCmd);
program.addCommand(tagsCmd);
program.addCommand(whoamiCmd);

setGlobalOptions(program.opts());

program.parse();