-
Notifications
You must be signed in to change notification settings - Fork 0
/
devtools.js
54 lines (50 loc) · 1.25 KB
/
devtools.js
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
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { getDocsClient } from "./parser/gdrive.js";
import { parseDoc } from "./parser/parser.js";
const getDocJSON = async (documentId) => {
const docsClient = await getDocsClient();
return (await docsClient.documents.get({ documentId })).data;
};
yargs(hideBin(process.argv))
.usage("Usage: $0 <command> [options]")
.command(
"json <googleDocID>",
"Get the JSON for an answer doc",
async ({
argv: {
_: [_, documentId],
},
}) => {
try {
const docJSON = await getDocJSON(documentId);
console.log(JSON.stringify(docJSON, null, 2));
} catch (e) {
if (e.code === 404) {
console.error("Invalid doc ID");
}
}
}
)
.command(
"md <googleDocID>",
"Get the rendered Markdown for an answer doc",
async ({
argv: {
_: [_, documentId],
},
}) => {
try {
const docJSON = await getDocJSON(documentId);
console.log((await parseDoc(docJSON)).md);
} catch (e) {
if (e.code === 404) {
console.error("Invalid doc ID");
} else {
console.error(e);
}
}
}
)
.help("h")
.alias("h", "help").argv;