-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogseq.ts
More file actions
executable file
·133 lines (128 loc) · 3.31 KB
/
logseq.ts
File metadata and controls
executable file
·133 lines (128 loc) · 3.31 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bun
/**
* LogSeq CLI
*
* A command-line interface for LogSeq operations.
* Requires LOGSEQ_API_TOKEN environment variable.
*
* Run with:
* bun run logseq <command> [options]
*
* Or compile and run as binary:
* bun build --compile logseq.ts --outfile logseq
* ./logseq <command> [options]
*
* Get help:
* bun run logseq help
* bun run logseq help <command>
*
* Page Commands:
* list-pages List all pages in the graph
* get-page Get content of a specific page
* create-page Create a new page
* update-page Update an existing page
* delete-page Delete a page
* search Search across the graph
*
* Block Commands:
* insert-block Create a new block
* edit-block Enter block editing mode
* exit-editing Exit editing mode
* get-page-blocks Get block tree for a page
*
* Context Commands:
* get-all-pages List all pages (with optional repo)
* get-current-page Get the currently active page or block
* get-current-blocks Get block tree of current page
* get-editing-content Get content of block being edited
*/
import {
listPages,
getPage,
createPage,
updatePage,
deletePage,
search,
insertBlock,
editBlock,
exitEditing,
getPageBlocks,
getAllPages,
getCurrentPage,
getCurrentBlocks,
getEditingContent,
} from "./cli/commands";
import { showHelp, showCommandHelp } from "./cli/help";
async function main(): Promise<void> {
const args = process.argv.slice(2);
const command = args[0];
const commandArgs = args.slice(1);
if (!command || command === "help" || command === "--help" || command === "-h") {
if (commandArgs[0]) {
showCommandHelp(commandArgs[0]);
} else {
showHelp();
}
return;
}
try {
switch (command) {
case "list-pages":
await listPages(commandArgs);
break;
case "get-page":
await getPage(commandArgs);
break;
case "create-page":
await createPage(commandArgs);
break;
case "update-page":
await updatePage(commandArgs);
break;
case "delete-page":
await deletePage(commandArgs);
break;
case "search":
await search(commandArgs);
break;
// Block operations
case "insert-block":
await insertBlock(commandArgs);
break;
case "edit-block":
await editBlock(commandArgs);
break;
case "exit-editing":
await exitEditing(commandArgs);
break;
// Context operations
case "get-all-pages":
await getAllPages(commandArgs);
break;
case "get-current-page":
await getCurrentPage(commandArgs);
break;
case "get-current-blocks":
await getCurrentBlocks(commandArgs);
break;
case "get-editing-content":
await getEditingContent(commandArgs);
break;
case "get-page-blocks":
await getPageBlocks(commandArgs);
break;
default:
console.error(`Unknown command: ${command}`);
showHelp();
process.exit(1);
}
} catch (error) {
if (error instanceof Error) {
console.error(`Error: ${error.message}`);
} else {
console.error("An unexpected error occurred");
}
process.exit(1);
}
}
main();