65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { OpenPGPSigner } from "../pdf_builder/utils.ts";
|
|
import {
|
|
add_index_to_pdf,
|
|
generate_md,
|
|
generate_pdf,
|
|
generate_txt,
|
|
sign_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();
|
|
}
|
|
|
|
if (options.sign_pdf) {
|
|
console.log("Signing PDF...");
|
|
|
|
// Pass optional passphrase from CLI options (e.g. --sign-passphrase)
|
|
const passphrase = options.sign_passphrase ?? options.passphrase ??
|
|
undefined;
|
|
await sign_pdf(passphrase);
|
|
}
|
|
break;
|
|
|
|
case "md":
|
|
await generate_md();
|
|
break;
|
|
case "txt":
|
|
await generate_txt();
|
|
break;
|
|
default:
|
|
throw new Error(`Unknown sub-command: ${sub_command[1]}`);
|
|
}
|
|
break;
|
|
default:
|
|
throw new Error(`Unknown sub-command: ${sub_command[0]}`);
|
|
}
|
|
}
|