Files
wpep/tools/gp/cli/match.ts
T
2026-04-29 16:02:43 +08:00

50 lines
1.3 KiB
TypeScript

import {
add_index_to_pdf,
generate_md,
generate_pdf,
use_qpdf,
} from "./handlers.ts";
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":
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":
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]}`);
}
}