improves block functionality
adds cli compatible prompts/logs adds logfile function for debug adds multiselect support new fieldRename adds listFieldNames
This commit is contained in:
29
cli/forceArgs.ts
Normal file
29
cli/forceArgs.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { cliPrompt } from "./prompts.ts";
|
||||
import type { TerminalBlock } from "./TerminalLayout.ts";
|
||||
|
||||
type prompt = [string, (v?: string) => boolean] | 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;
|
||||
}
|
Reference in New Issue
Block a user