This commit is contained in:
:NoBody: committed 2026-04-29 16:02:43 +08:00
1 parent 115fd47bae
commit 76bd7cd645
78 files changed
+5041 -187

No files matched your search

+36 -4
View File
@@ -1,16 +1,48 @@
import { generate_md, generate_pdf } from "./handlers.ts";
import {
add_index_to_pdf,
generate_md,
generate_pdf,
use_qpdf,
} from "./handlers.ts";
export function match_sub_command_to_function(sub_command: Array<string>) {
export async function match_sub_command_to_function(
sub_command: Array<string>,
options: Record<string, any>,
) {
switch (sub_command[0]) {
case "generate":
switch (sub_command[1]) {
case "pdf":
return generate_pdf;
await generate_pdf();
if (
options.add_index != false && options.add_index != undefined
) {
console.log(
`add_index option is set to ${options.add_index}. Adding index to PDF...`,
);
if (typeof options.add_index === "boolean") {
await add_index_to_pdf();
} else if (typeof options.add_index === "number") {
await add_index_to_pdf(options.add_index);
} else {
console.warn(
`Invalid value for add_index: ${options.add_index}. Expected boolean or number. Skipping index addition.`,
);
}
}
if (options.use_qpdf) {
await use_qpdf();
}
break;
case "md":
return generate_md;
await generate_md();
break;
default:
throw new Error(`Unknown sub-command: ${sub_command[1]}`);
}
break;
default:
throw new Error(`Unknown sub-command: ${sub_command[0]}`);
}