pdf-tools/cli/forceArgs.ts
Emmaline 7c19ada88b feat: delete fields tool
fix: field rename
fix: list fields now scrolls
2025-06-06 10:50:27 -06:00

30 lines
758 B
TypeScript

import { cliPrompt } from "./prompts.ts";
import type { TerminalBlock } from "./TerminalLayout.ts";
type prompt = [string, (v?: string) => boolean | undefined] | string;
export async function forceArgs(
args: string[],
prompts: prompt[],
block?: TerminalBlock,
) {
const newArgs: string[] = [];
for (const [i, arg] of args.entries()) {
if (typeof prompts[i] === "string") {
let val = arg;
while (!val) {
val = await cliPrompt(prompts[i], block) || "";
}
newArgs.push(val);
} else {
const [promptText, validation] = prompts[i];
let val = arg;
while (!validation(val)) {
val = await cliPrompt(promptText, block) || "";
}
newArgs.push(val);
}
}
return newArgs;
}