aboutsummaryrefslogtreecommitdiffstats
path: root/apps/cli/commands/lists.ts
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-04-24 11:08:30 +0100
committerMohamedBassem <me@mbassem.com>2024-04-24 11:08:30 +0100
commitaf0cf9c1ee10901ab91b04a1d73afdcb2191a88f (patch)
treec1d46b198ef7964fbc2199477affc96ed2016932 /apps/cli/commands/lists.ts
parent5dac180f486cbc6bb202debd5dde996a9c8204b4 (diff)
downloadkarakeep-af0cf9c1ee10901ab91b04a1d73afdcb2191a88f.tar.zst
feature(cli): Add ability to manipulate lists, tags and update bookmarks
Diffstat (limited to 'apps/cli/commands/lists.ts')
-rw-r--r--apps/cli/commands/lists.ts74
1 files changed, 74 insertions, 0 deletions
diff --git a/apps/cli/commands/lists.ts b/apps/cli/commands/lists.ts
new file mode 100644
index 00000000..099b7869
--- /dev/null
+++ b/apps/cli/commands/lists.ts
@@ -0,0 +1,74 @@
+import { Command } from "@commander-js/extra-typings";
+import { getAPIClient } from "lib/trpc";
+import { getBorderCharacters, table } from "table";
+
+import { listsToTree } from "@hoarder/shared/utils/listUtils";
+
+export const listsCmd = new Command()
+ .name("lists")
+ .description("Manipulating lists");
+
+listsCmd
+ .command("list")
+ .description("Lists all lists")
+ .action(async () => {
+ const api = getAPIClient();
+
+ const resp = await api.lists.list.query();
+ const { allPaths } = listsToTree(resp.lists);
+
+ const data: string[][] = [["Id", "Name"]];
+
+ allPaths.forEach((path) => {
+ const name = path.map((p) => `${p.icon} ${p.name}`).join(" / ");
+ const id = path[path.length - 1].id;
+ data.push([id, name]);
+ });
+ console.log(
+ table(data, { border: getBorderCharacters("ramac"), singleLine: true }),
+ );
+ });
+
+listsCmd
+ .command("delete")
+ .description("Deletes a list")
+ .argument("<id>", "The id of the list")
+ .action(async (id) => {
+ const api = getAPIClient();
+
+ await api.lists.delete.mutate({
+ listId: id,
+ });
+ console.log("Successfully deleted list with id:", id);
+ });
+
+listsCmd
+ .command("add-bookmark")
+ .description("Add a bookmark to list")
+ .requiredOption("--list <id>", "The id of the list")
+ .requiredOption("--bookmark <bookmark>", "The id of the bookmark")
+ .action(async (opts) => {
+ const api = getAPIClient();
+
+ await api.lists.addToList.mutate({
+ listId: opts.list,
+ bookmarkId: opts.bookmark,
+ });
+ console.log("Successfully added bookmark from list");
+ });
+
+listsCmd
+ .command("remove-bookmark")
+ .description("Remove a bookmark from list")
+ .requiredOption("--list <id>", "The id of the list")
+ .requiredOption("--bookmark <bookmark>", "The id of the bookmark")
+ .action(async (opts) => {
+ const api = getAPIClient();
+
+ await api.lists.removeFromList.mutate({
+ listId: opts.list,
+ bookmarkId: opts.bookmark,
+ });
+
+ console.log("Successfully removed bookmark from list");
+ });